//========================================================================
//  SE5 AI Global Settings - Captain Kwok's Balance Mod v125+
//========================================================================
//
// Balance Mod Changes
// -------------------
// v1.29 Changed - Further adjustments to ship demand modifiers
//       Changed - Allow AI players to contribute more trade income for maintenance costs
//       Changed - Added override for vehicle wanted amounts (negative number is converted to an actual positive target number)
//       Fixed   - Defense Drone numbers were being based on Bombardment Drones (mostly not being built by computer players)
//       Fixed   - Minor fixes to ship/unit ratios for adjustment the demand per one factor
// v1.27 Changed - Removed escort and picket role references
// v1.26 Changed - Low maintenance, high resource modifier for ships increased to 1.5 from 1.2
// v1.25 Changed - Various updates for changes to vehicle sizes
//       Added   - Tracking for game settings like colonization restrictions and quadrant density
//       Added   - Coop level values for each treaty element
//       Added   - Support for new design types
//       Added   - Updated settings for changes to facilities
//       Added   - Emergency provision to add a few resources to the AI's storage if it goes bankrupt
// v1.23 Fixed   - It was possible under very rare circumstances that a divide by 0 error could error when calculating trade income to use for maintenance
// v1.21 Added   - Support for ModAITreatySettings.txt to restrict certain AI behaviours
// v1.20 Changed - Updated design type name references
//       Fixed   - AI players were not using Temporal Space Yard Facilities
// v1.19 Changed - Added modifiers to adjust an AI's queue demand when it has the Ancient Race trait
//       Changed - AIs will match desired resource ratios to actual resource usage
//       Changed - Made improvements to the AI's interpretation of their resource situation (v1.19a)
//       Fixed   - Error in AI's determination if it was alone or not (v1.19c)
//       Added   - Fx[Set_Race_Point_Modifiers] to maintain research-intel point production balance (v1.19c)
//       Changed - Reduced demand for ship and units when the AI is in a disconnected state (v1.19c)
//       Fixed   - Some facility ID variables would point to the same facility twice or more (v1.19d)
//       Fixed   - Error in demand for Missile Satellites (v1.19d)
//       Added   - Friendship value for each treaty element value (v1.19h)
//       Changed - Revised demand calculations for design type (v1.19h)
//       Changed - Improved demand calculations for colonizers (v1.19i)
//       Fixed   - Error in demand calculation for Point-Defense Satellites (v1.19j)
// v1.18 Changed - Adjusted conditions for low and high resource states
// v1.17 Changed - Utilized more hull sizes for AI design types
// v1.15 Changed - Updated AI design type names
//       Changed - The AI will consider itself in a low resource state to be when it has less than 10% stored of what it can produce
//       Removed - Fx[AI_Set_Political_Anger_Severity_Time]
//       Added   - Modified conditions for when the AI should build certain design types
//       Changed - Adjusted various demand values for vehicles
//       Changed - Adjusted Neutral race's design type choices
// v1.14 Changed - Expanded the design type list to allow for multiple instances of the same design type with different hull sizes
//       Fixed   - Temporal Space Yards were not being selected ahead of regular Space Yards
//       Fixed   - Error in facility IDs for resource system modifier facilities
//       Changed - Added back support for Cargo Transports
//       Changed - Made tweaks to how the AI calculates it's maximum amount to spend on maintenance
// v1.13 Changed - Demand values for design types now based on current facility count, rather than projected count
// v1.12 Changed - Revised Alliance element anger values
//       Changed - Added a cap for remote resource vehicles
// v1.10 Changed - Conditions for different resource states in Fx[Set_Race_Resource_Modifiers]
//       Added   - New Fx[AI_Set_Game_Settings]
//       Changed - AI will use carrier vehicles for Drone Carrier design type
//       Changed - Adjusted parameters for setting AI resource indicator variables
//       Changed - Re-arranged facility ID settings
//       Changed - Re-worked demand values for design types
//       Changed - Revised Alliance anger element values
// v1.08 Changed - Modified demand rates based on Empire's design type preferences
//       Changed - Modified demand rates for races that use lots of fighters
// v1.07 Added   - Support for new AI design types
// v1.06 Added   - New Fx[AI_Set_Facility_Id] from Script_AI_Construction.txt
//       Changed - Moved Fx[AI_Get_Number_Of_Wars] to Script_AI_GlobalFunctions.txt
//       Changed - Adjusted demand values for some design types
//       Added   - Support for Medical and Remote Mining ships
//       Added   - New Fx[Set_Race_Resource_Modifiers]
// v1.05 Changed - Adjusted anger severity values for most event/message types
//       Fixed   - Some maximum anger amounts did not make sense in game terms
//       Added   - New Fx[AI_Get_Number_Of_Wars]
// v1.04 Changed - Optimized settings in Fx[AI_Set_Vehicle_Sizes], removed variables for number of engines, LS, CQ etc.
//       Changed - Implemented new ship purchasing scheme
//       Fixed   - Bases will add Supply Storage when they are using Quantum Reactors
//       Added   - Support for Scout and Patrol Ship designs
// v1.03 Changed - Only combat designs with ordnance usage will add Ordnance Storage
// v1.02 Changed - Life Support and Crew Quarters amounts in Fx[AI_Set_Vehicle_Sizes] are now actual crew amounts
//       Fixed   - Error in adding Bombardment Ship design types priorities
// v1.01 Fixed   - Error in number of engines for Small Crystalline Fighter in Fx[AI_Set_Vehicle_Sizes]
//       Changed - Adjusted some anger values for treaty elements in Fx[AI_Set_Political_Treaty_Elements]
//       Added   - Descriptive comments for treaty elements in Fx[AI_Set_Political_Treaty_Elements]
// v1.00 Changed - Increased demand for unit construction
//       Changed - Modified severity values for log events
//       Changed - Reduced demand for Anti-Planet Drones
//       Changed - Updated engine amounts to reflect changes in the mod
// v0.99 Added   - Support for Bombardment Ship design type
// v0.97 Added   - Support for new drone types in Fx[AI_Set_Race_Design_Types]
//       Added   - More conditions to control what design types extra components are added to in Fx[AI_Add_Extra_Comps]
//       Changed - Reduced crew requirements for most ship types in Fx[AI_Set_Vehicle_Sizes]
// v0.96 Added   - Support for Defense Ships in Fx[AI_Set_Race_Design_Types]
//       Changed - Re-ordered list of design types for the AI to purchase in Fx[AI_Set_Race_Design_Types]
// v0.95 Changed - Updated requirements for Destroyers, Light Cruisers, and Carriers in Fx[AI_Set_Vehicle_Sizes]
//       Changed - Took out some more treaty options to help the AI in Fx[AI_Set_Political_Treaty_Elements]
// v0.92 Updated - Further tweaking of priorities for different design types
// v0.90 Changed - Edited Fx[AI_Set_Race_Design_Types] to increase priorities for certain ship types and units
// v0.72 Added   - Support for new design types in Fx[AI_Set_Race_Design_Types]
// v0.20 Updated - Updated requirements for Balance mod vehicle sizes in Fx[AI_Set_Vehicle_Sizes]
//
// Balance Mod To-do List:
// -----------------------
// - Nothing pending
//
// Script Function Requests:
// -------------------------
// - Sys_Get_Maximum_Ships_Allowed() : long
// - Sys_Get_Maximum_Units_In_Space_Allowed() : long
// - Sys_Get_Colonization_Restrictions() : Long

//------------------------------------------------------------------------
// Set_Game_Settings
//------------------------------------------------------------------------
function Set_Game_Settings returns boolean
vars
  num_players:               long
  plr_index:                 long
  datafile_id:               long
  datafile_value:            string
begin

  // Debug output
  call Sys_Debug_Print("Enemy Analysis", "Game Settings:")
  call Sys_Debug_Print("Enemy Analysis", "--------------")

  // Get the number of players
  set num_players := Sys_Get_Number_Of_Players()

  // Note our difficulty level
  case Sys_Game_Settings_Get_AI_Difficulty()
    1:
      set lng_AI_Difficulty := AI_DIFFICULTY_EASY
      call Sys_Debug_Print("Enemy Analysis", "  - Difficulty = Easy")
    2:
      set lng_AI_Difficulty := AI_DIFFICULTY_MEDIUM
      call Sys_Debug_Print("Enemy Analysis", "  - Difficulty = Medium")
    3:
      set lng_AI_Difficulty := AI_DIFFICULTY_HARD
      call Sys_Debug_Print("Enemy Analysis", "  - Difficulty = Hard")
  endcase

  // Are we a computer player?
  set bool_Are_We_Computer_Player := Sys_Are_We_Computer_Player(sys_long_Player_ID)

  // Debug output
  if (bool_Are_We_Computer_Player) then
    call Sys_Debug_Print("Enemy Analysis", "  - AI player")
  endif

  // Are we a neutral player?
  set bool_Are_We_Neutral_Player := Sys_Are_We_Neutral_Empire(sys_long_Player_ID)

  // Debug output
  if (bool_Are_We_Neutral_Player) then
    call Sys_Debug_Print("Enemy Analysis", "  - Neutral player")
  endif

  // Do we know other races?
  if (Sys_Empire_Politics_Get_Number_Of_Known_Players(sys_long_Player_ID) > 1) then
    set bool_Race_Is_Not_Alone := TRUE
  endif

  // Game settings
  set bool_AI_Team_Mode_On := Sys_Is_Game_Using_Teams()
  set bool_Race_At_Max_Tech := Sys_Empire_Research_All_Techs_Researched(sys_long_Player_ID)
  set bool_Intel_Is_Allowed := Sys_Is_Game_Using_Intelligence()
  set bool_Race_At_Max_Ships := At_Max_Ships()
  set bool_Race_At_Max_Units := At_Max_Units()

  // Debug output
  if (bool_AI_Team_Mode_On) then
    call Sys_Debug_Print("Enemy Analysis", "  - AI Team Mode")
  endif

  // Colonization restrictions
  set bool_Colonize_Only_Breathable := Check_For_Colonization_Game_Restrictions(sys_long_Player_ID, TRUE, FALSE)
  set bool_Colonize_Only_Home_Type := Check_For_Colonization_Game_Restrictions(sys_long_Player_ID, FALSE, TRUE)

  if (bool_Colonize_Only_Breathable) and (bool_Colonize_Only_Home_Type) then
    set bool_Colonize_Only_Home_And_Breathable := TRUE
    set bool_Colonize_All_Types := FALSE
    set bool_Colonize_Only_Breathable := FALSE
    set bool_Colonize_Only_Home_Type := FALSE
  else
    if (bool_Colonize_Only_Breathable) or (bool_Colonize_Only_Home_Type) then
      set bool_Colonize_All_Types := FALSE
    endif
  endif

  // Debug output
  if (bool_Colonize_All_Types) then
    call Sys_Debug_Print("Enemy Analysis", "  - No Colonization Restrictions")
  endif
  if (bool_Colonize_Only_Breathable) then
    call Sys_Debug_Print("Enemy Analysis", "  - Colonize Breathable Atmospheres Only")
  endif
  if (bool_Colonize_Only_Home_Type) then
    call Sys_Debug_Print("Enemy Analysis", "  - Colonize Home Planet Type Only")
  endif
  if (bool_Colonize_Only_Home_And_Breathable) then
    call Sys_Debug_Print("Enemy Analysis", "  - Colonize Home Planet Type and Breathable Only")
  endif

  // Quadrant Location
  set lng_AI_Quadrant_Location_Score := Compute_Quadrant_Location()
  // Debug output
  call Sys_Debug_Print("Enemy Analysis", "  - Quadrant location score = " + Sys_Convert_Long_To_String(lng_AI_Quadrant_Location_Score))

  if (lng_AI_Quadrant_Location_Score <= 25) then
    set lng_AI_Quadrant_Location := QUADRANT_LOCATION_CENTER
    // Debug output
    call Sys_Debug_Print("Enemy Analysis", "    - Quadrant Location = Center")
  else
    if (lng_AI_Quadrant_Location_Score > 25) and (lng_AI_Quadrant_Location_Score <= 30) then
      set lng_AI_Quadrant_Location := QUADRANT_LOCATION_MIDDLE
      // Debug output
      call Sys_Debug_Print("Enemy Analysis", "    - Quadrant Location = Middle")
    else
      if (lng_AI_Quadrant_Location_Score > 30) and (lng_AI_Quadrant_Location_Score < 35) then
        set lng_AI_Quadrant_Location := QUADRANT_LOCATION_EDGE
        // Debug output
        call Sys_Debug_Print("Enemy Analysis", "    - Quadrant Location = Edge")
      else
        set lng_AI_Quadrant_Location := QUADRANT_LOCATION_CORNER
        // Debug output
        call Sys_Debug_Print("Enemy Analysis", "    - Quadrant Location = Corner")
      endif
    endif
  endif

  // Quadrant Density
  set lng_AI_Quadrant_Density := Get_Systems_Per_Player()
  
  if (lng_AI_Quadrant_Density >= QUADRANT_SYS_DENSITY_LOW) then
    set bool_Quadrant_Density_Low := TRUE
    call Sys_Debug_Print("Enemy Analysis", "  - Quadrant Density Low (" + Sys_Convert_Long_To_String(lng_AI_Quadrant_Density) + ")")
  else
    if (lng_AI_Quadrant_Density >= QUADRANT_SYS_DENSITY_MEDIUM) then
      set bool_Quadrant_Density_Medium := TRUE
      call Sys_Debug_Print("Enemy Analysis", "  - Quadrant Density Medium (" + Sys_Convert_Long_To_String(lng_AI_Quadrant_Density) + ")")
    else
      set bool_Quadrant_Density_High := TRUE
      call Sys_Debug_Print("Enemy Analysis", "  - Quadrant Density High (" + Sys_Convert_Long_To_String(lng_AI_Quadrant_Density) + ")")
    endif
  endif

  // Mod Game Settings
  // Special AI Treaty Settings
  set datafile_id := Sys_Load_Datafile(sys_long_Player_ID, "ModAITreatySettings.txt")

  // Apply the mod's custom AI treaty settings
  if (datafile_id > 0) then
    // Trade
    set datafile_value := Sys_Get_Datafile_Field_Value_As_String(datafile_id, "Allow Trade")
    set bool_ModAITreatySetting_Allow_Trade := (datafile_value = "TRUE")
    set datafile_value := Sys_Get_Datafile_Field_Value_As_String(datafile_id, "Offer Trade")
    set bool_ModAITreatySetting_Offer_Trade := (datafile_value = "TRUE")
    // Migration
    set datafile_value := Sys_Get_Datafile_Field_Value_As_String(datafile_id, "Allow Migration")
    set bool_ModAITreatySetting_Allow_Migration := (datafile_value = "TRUE")
    set datafile_value := Sys_Get_Datafile_Field_Value_As_String(datafile_id, "Offer Migration")
    set bool_ModAITreatySetting_Offer_Migration := (datafile_value = "TRUE")
    // Colonization
    set datafile_value := Sys_Get_Datafile_Field_Value_As_String(datafile_id, "Allow Colonization")
    set bool_ModAITreatySetting_Allow_Colonization := (datafile_value = "TRUE")
    set datafile_value := Sys_Get_Datafile_Field_Value_As_String(datafile_id, "Offer Colonization")
    set bool_ModAITreatySetting_Offer_Colonization := (datafile_value = "TRUE")
    // Share Technology
    set datafile_value := Sys_Get_Datafile_Field_Value_As_String(datafile_id, "Allow Share Technology")
    set bool_ModAITreatySetting_Allow_Share_Technology := (datafile_value = "TRUE")
    set datafile_value := Sys_Get_Datafile_Field_Value_As_String(datafile_id, "Offer Share Technology")
    set bool_ModAITreatySetting_Offer_Share_Technology := (datafile_value = "TRUE")
    // Share Maps
    set datafile_value := Sys_Get_Datafile_Field_Value_As_String(datafile_id, "Allow Share Maps")
    set bool_ModAITreatySetting_Allow_Share_Maps := (datafile_value = "TRUE")
    set datafile_value := Sys_Get_Datafile_Field_Value_As_String(datafile_id, "Offer Share Maps")
    set bool_ModAITreatySetting_Offer_Share_Maps := (datafile_value = "TRUE")
    // Share Comm Channels
    set datafile_value := Sys_Get_Datafile_Field_Value_As_String(datafile_id, "Allow Share Comm Channels")
    set bool_ModAITreatySetting_Allow_Share_Comm_Channels := (datafile_value = "TRUE")
    set datafile_value := Sys_Get_Datafile_Field_Value_As_String(datafile_id, "Offer Share Comm Channels")
    set bool_ModAITreatySetting_Offer_Share_Comm_Channels := (datafile_value = "TRUE")
    // Share Espionage Info
    set datafile_value := Sys_Get_Datafile_Field_Value_As_String(datafile_id, "Allow Share Espionage Info")
    set bool_ModAITreatySetting_Allow_Share_Espionage_Info := (datafile_value = "TRUE")
    set datafile_value := Sys_Get_Datafile_Field_Value_As_String(datafile_id, "Offer Share Espionage Info")
    set bool_ModAITreatySetting_Offer_Share_Espionage_Info := (datafile_value = "TRUE")
    // Share Sensor Info
    set datafile_value := Sys_Get_Datafile_Field_Value_As_String(datafile_id, "Allow Share Sensor Info")
    set bool_ModAITreatySetting_Allow_Share_Sensor_Info := (datafile_value = "TRUE")
    set datafile_value := Sys_Get_Datafile_Field_Value_As_String(datafile_id, "Offer Share Sensor Info")
    set bool_ModAITreatySetting_Offer_Share_Sensor_Info := (datafile_value = "TRUE")
    // Share Vehicle Designs
    set datafile_value := Sys_Get_Datafile_Field_Value_As_String(datafile_id, "Allow Share Vehicle Designs")
    set bool_ModAITreatySetting_Allow_Share_Vehicle_Designs := (datafile_value = "TRUE")
    set datafile_value := Sys_Get_Datafile_Field_Value_As_String(datafile_id, "Offer Share Vehicle Designs")
    set bool_ModAITreatySetting_Offer_Share_Vehicle_Designs := (datafile_value = "TRUE")
    // Share Combat Reports
    set datafile_value := Sys_Get_Datafile_Field_Value_As_String(datafile_id, "Allow Share Combat Reports")
    set bool_ModAITreatySetting_Allow_Share_Combat_Reports := (datafile_value = "TRUE")
    set datafile_value := Sys_Get_Datafile_Field_Value_As_String(datafile_id, "Offer Share Combat Reports")
    set bool_ModAITreatySetting_Offer_Share_Combat_Reports := (datafile_value = "TRUE")
    // Share Minefield Codes
    set datafile_value := Sys_Get_Datafile_Field_Value_As_String(datafile_id, "Allow Share Minefield Codes")
    set bool_ModAITreatySetting_Allow_Share_Minefield_Codes := (datafile_value = "TRUE")
    set datafile_value := Sys_Get_Datafile_Field_Value_As_String(datafile_id, "Offer Share Minefield Codes")
    set bool_ModAITreatySetting_Offer_Share_Minefield_Codes := (datafile_value = "TRUE")

  endif

  call Sys_Unload_Datafile(datafile_id)

  // Is it still early game?
  if ((sys_long_Game_Date - Sys_Get_Game_Start_Date()) < 50) then
    set bool_Early_Game := TRUE
  endif

  // Note our special racial traits
  set bool_Race_Does_Not_Use_Spaceports := Sys_Does_Empire_Have_Ability(sys_long_Player_ID, "Points Added to Empire Pool")
  set bool_Race_Is_Ancient_Race := Sys_Does_Empire_Have_Ability(sys_long_Player_ID, "Empire - All Systems Seen At Start")

  // Note
  if (num_players > 0) then
    for plr_index := 1 to num_players do
      // Note our Non-Aggression status
      call lst_Politics_Non_Aggression_Level.add(Get_Non_Aggression_Status(plr_index))
      // Is there a mega evil player?
      if Sys_Empire_Politics_Is_Player_The_Ultimate_Evil(sys_long_Player_ID, plr_index) then
        set bool_Mega_Evil_Activated := TRUE
        set lng_Politics_Mega_Evil_Player := plr_index
        // Debug Output
        call Sys_Debug_Print("Enemy Analysis", "  - Mega Evil Active! (" + Sys_Empire_Get_Empire_Name(plr_index) ")")
      endif
    endfor
  endif

  return TRUE
end

//------------------------------------------------------------------------
// Set_Design_Suffixes
//------------------------------------------------------------------------
function Set_Design_Suffixes returns boolean
vars
begin

  // Make a list of Design Suffixes
  call lst_AI_Design_Suffixes.add(" I")
  call lst_AI_Design_Suffixes.add(" II")
  call lst_AI_Design_Suffixes.add(" III")
  call lst_AI_Design_Suffixes.add(" IV")
  call lst_AI_Design_Suffixes.add(" V")
  call lst_AI_Design_Suffixes.add(" VI")
  call lst_AI_Design_Suffixes.add(" VII")
  call lst_AI_Design_Suffixes.add(" VIII")
  call lst_AI_Design_Suffixes.add(" IX")
  call lst_AI_Design_Suffixes.add(" X")
  call lst_AI_Design_Suffixes.add(" XI")
  call lst_AI_Design_Suffixes.add(" XII")
  call lst_AI_Design_Suffixes.add(" XIII")
  call lst_AI_Design_Suffixes.add(" XIV")
  call lst_AI_Design_Suffixes.add(" XV")
  call lst_AI_Design_Suffixes.add(" XVI")
  call lst_AI_Design_Suffixes.add(" XVII")
  call lst_AI_Design_Suffixes.add(" XVIII")
  call lst_AI_Design_Suffixes.add(" XIX")
  call lst_AI_Design_Suffixes.add(" XX")
  call lst_AI_Design_Suffixes.add(" XXI")
  call lst_AI_Design_Suffixes.add(" XXII")
  call lst_AI_Design_Suffixes.add(" XXIII")
  call lst_AI_Design_Suffixes.add(" XXIV")
  call lst_AI_Design_Suffixes.add(" XXV")
  call lst_AI_Design_Suffixes.add(" XXVI")
  call lst_AI_Design_Suffixes.add(" XXVII")
  call lst_AI_Design_Suffixes.add(" XXVIII")
  call lst_AI_Design_Suffixes.add(" XXIX")
  call lst_AI_Design_Suffixes.add(" XXX")

  return TRUE
end

//------------------------------------------------------------------------
// Set_Facility_Id
//------------------------------------------------------------------------
function Set_Facility_Id returns boolean
vars
  facility_id:               long
begin

  // Get the facility id that matches our desired ability
  set lng_facility_id_spaceport := Sys_Get_Facility_ID("Space Port")
  set lng_facility_id_resupply_depot := Sys_Get_Facility_ID("Resupply Depot")

  if (Sys_Get_Highest_Facility_Level(sys_long_Player_ID, Sys_Get_Facility_ID("Temporal Space Yard Facility")) > 0) then
    set lng_facility_id_space_yard := Sys_Get_Facility_ID("Temporal Space Yard Facility")
  else
    set lng_facility_id_space_yard := Sys_Get_Best_Facility_With_Ability(sys_long_Player_ID, "Space Yard")
  endif

  // Resource facilities
  set lng_facility_id_minerals := Sys_Get_Facility_ID("Mineral Miner Facility")
  set lng_facility_id_organics := Sys_Get_Facility_ID("Organics Farm Facility")
  set lng_facility_id_radioactives := Sys_Get_Facility_ID("Radioactives Extraction Facility")
  set lng_facility_id_monolith := Sys_Get_Facility_ID("Monolith Facility")
  set lng_facility_id_minerals_mod := Sys_Get_Facility_ID("Mineral Scanner")
  set lng_facility_id_minerals_sys_mod := Sys_Get_Facility_ID("System Mineral Scanner")
  set lng_facility_id_organics_mod := Sys_Get_Facility_ID("Hybrid Eco-Farms")
  set lng_facility_id_organics_sys_mod := Sys_Get_Facility_ID("System Eco-Farms")
  set lng_facility_id_radioactives_mod := Sys_Get_Facility_ID("Radioactives Collider")
  set lng_facility_id_radioactives_sys_mod := Sys_Get_Facility_ID("System Radioactives Collider")
  set lng_facility_id_comp_factory := Sys_Get_Facility_ID("Components Factory")
  set lng_facility_id_sys_robotoid := Sys_Get_Facility_ID("System Robotoid Factory")
  set lng_facility_id_resource_conversion := Sys_Get_Facility_ID("Resource Converter")
  set lng_facility_id_resource_reclamation := Sys_Get_Facility_ID("Ultra-Recycler")

  // Research and intel facilities
  set lng_facility_id_research_pts := Sys_Get_Facility_ID("Research Center")
  set lng_facility_id_research_pts_mod := Sys_Get_Facility_ID("Central Computer Complex")
  set lng_facility_id_research_pts_sys_mod := Sys_Get_Facility_ID("Research Directorate")
  set lng_facility_id_intel_pts := Sys_Get_Facility_ID("Intelligence Center")
  set lng_facility_id_intel_pts_mod := Sys_Get_Facility_ID("Citizen Databank Complex")
  set lng_facility_id_intel_pts_sys_mod := Sys_Get_Facility_ID("Intelligence Directorate")

  // Population support facilities
  set lng_facility_id_plague_prevention := Sys_Get_Best_Facility_With_Ability(sys_long_Player_ID, "Plague Prevention")
  set lng_facility_id_pop_happiness := Sys_Get_Best_Facility_With_Ability(sys_long_Player_ID, "Planet Population Happiness")
  set lng_facility_id_pop_reproduction := Sys_Get_Facility_ID("Gestation Vats")
  set lng_facility_id_pop_amount := Sys_Get_Best_Facility_With_Ability(sys_long_Player_ID, "Planet Population Amount")

  // Planet modification facilities
  set lng_facility_id_planet_value := Sys_Get_Best_Facility_With_Ability(sys_long_Player_ID, "Planet Value - Minerals")
  set lng_facility_id_planet_conditions := Sys_Get_Best_Facility_With_Ability(sys_long_Player_ID, "Planet Conditions Change")
  set lng_facility_id_planet_atmosphere := Sys_Get_Best_Facility_With_Ability(sys_long_Player_ID, "Planet Atmosphere Change")

  // Ship and fleet support facilities
  set lng_facility_id_ship_training := Sys_Get_Best_Facility_With_Ability(sys_long_Player_ID, "Ship Training")
  set lng_facility_id_fleet_training := Sys_Get_Best_Facility_With_Ability(sys_long_Player_ID, "Fleet Training")

  // Shield facilities
  set lng_facility_id_shield_pts := Sys_Get_Best_Facility_With_Ability(sys_long_Player_ID, "Shield Generation")
  set lng_facility_id_sys_shield := Sys_Get_Best_Facility_With_Ability(sys_long_Player_ID, "Stop Star Destroyer")

  // Storage facilities
  set lng_facility_id_minerals_storage := Sys_Get_Best_Facility_With_Ability(sys_long_Player_ID, "Resource Storage - Minerals")
  set lng_facility_id_organics_storage := Sys_Get_Best_Facility_With_Ability(sys_long_Player_ID, "Resource Storage - Organics")
  set lng_facility_id_radioactives_storage := Sys_Get_Best_Facility_With_Ability(sys_long_Player_ID, "Resource Storage - Radioactives")
  set lng_facility_id_cargo_storage := Sys_Get_Best_Facility_With_Ability(sys_long_Player_ID, "Storage Space Amount")

  // Racial trait facilities
  set lng_facility_id_events_mod := Sys_Get_Best_Facility_With_Ability(sys_long_Player_ID, "Bad Event Chance")
  set lng_facility_id_shield_mod := Sys_Get_Best_Facility_With_Ability(sys_long_Player_ID, "Shield Modifier")
  set lng_facility_id_combat_mod := Sys_Get_Best_Facility_With_Ability(sys_long_Player_ID, "Combat Modifier")
  set lng_facility_id_damage_mod := Sys_Get_Best_Facility_With_Ability(sys_long_Player_ID, "Damage Modifier")
  set lng_facility_id_maint_mod := Sys_Get_Best_Facility_With_Ability(sys_long_Player_ID, "Ship Maintenance Cost Modifier")
  set lng_facility_id_prod_mod := Sys_Get_Facility_ID("Time Shrine")
  set lng_facility_id_value_mod := Sys_Get_Facility_ID("Nature Shrine")
  set lng_facility_id_solar_resources := Sys_Get_Best_Facility_With_Ability(sys_long_Player_ID, "Solar Resource Generation - Minerals")
  set lng_facility_id_scanner := Sys_Get_Best_Facility_With_Ability(sys_long_Player_ID, "Long Range Scanner")
  set lng_facility_id_extra_facility_space := Sys_Get_Best_Facility_With_Ability(sys_long_Player_ID, "Storage Facility Space Amount")
  set lng_facility_id_dimensional_rift := Sys_Get_Facility_ID("Dimensional Rift Projector")
  set lng_facility_id_allegiance_subverter := Sys_Get_Facility_ID("Allegiance Subverter Amplifier")

end

//------------------------------------------------------------------------
// Set_Vehicle_Sizes
//------------------------------------------------------------------------
function Set_Vehicle_Sizes returns boolean
vars
begin

  call lst_AI_Vehicle_Sizes_Name.add("Frigate")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_FRIGATE)
  call lst_AI_Vehicle_Sizes_Name.add("Organic Frigate")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_FRIGATE)
  call lst_AI_Vehicle_Sizes_Name.add("Crystalline Frigate")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_FRIGATE)

  call lst_AI_Vehicle_Sizes_Name.add("Destroyer")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_DESTROYER)
  call lst_AI_Vehicle_Sizes_Name.add("Organic Destroyer")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_DESTROYER)
  call lst_AI_Vehicle_Sizes_Name.add("Crystalline Destroyer")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_DESTROYER)

  call lst_AI_Vehicle_Sizes_Name.add("Light Cruiser")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_LIGHT_CRUISER)
  call lst_AI_Vehicle_Sizes_Name.add("Organic Light Cruiser")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_LIGHT_CRUISER)
  call lst_AI_Vehicle_Sizes_Name.add("Crystalline Light Cruiser")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_LIGHT_CRUISER)

  call lst_AI_Vehicle_Sizes_Name.add("Cruiser")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_CRUISER)
  call lst_AI_Vehicle_Sizes_Name.add("Organic Cruiser")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_CRUISER)
  call lst_AI_Vehicle_Sizes_Name.add("Crystalline Cruiser")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_CRUISER)

  call lst_AI_Vehicle_Sizes_Name.add("Battleship")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_BATTLESHIP)
  call lst_AI_Vehicle_Sizes_Name.add("Organic Battleship")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_BATTLESHIP)
  call lst_AI_Vehicle_Sizes_Name.add("Crystalline Battleship")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_BATTLESHIP)

  call lst_AI_Vehicle_Sizes_Name.add("Dreadnought")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_DREADNOUGHT)
  call lst_AI_Vehicle_Sizes_Name.add("Organic Dreadnought")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_DREADNOUGHT)
  call lst_AI_Vehicle_Sizes_Name.add("Crystalline Dreadnought")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_DREADNOUGHT)

  call lst_AI_Vehicle_Sizes_Name.add("Baseship")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_BASESHIP)
  call lst_AI_Vehicle_Sizes_Name.add("Organic Baseship")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_BASESHIP)
  call lst_AI_Vehicle_Sizes_Name.add("Crystalline Baseship")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_BASESHIP)

  if (bool_Race_Uses_Fighters) then
    call lst_AI_Vehicle_Sizes_Name.add("Light Carrier")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_LIGHT_CARRIER)
    call lst_AI_Vehicle_Sizes_Name.add("Organic Light Carrier")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_LIGHT_CARRIER)
    call lst_AI_Vehicle_Sizes_Name.add("Crystalline Light Carrier")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_LIGHT_CARRIER)

    call lst_AI_Vehicle_Sizes_Name.add("Carrier")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_CARRIER)
    call lst_AI_Vehicle_Sizes_Name.add("Organic Carrier")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_CARRIER)
    call lst_AI_Vehicle_Sizes_Name.add("Crystalline Carrier")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_CARRIER)

    call lst_AI_Vehicle_Sizes_Name.add("Heavy Carrier")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_HEAVY_CARRIER)
    call lst_AI_Vehicle_Sizes_Name.add("Organic Heavy Carrier")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_HEAVY_CARRIER)
    call lst_AI_Vehicle_Sizes_Name.add("Crystalline Heavy Carrier")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_HEAVY_CARRIER)
  endif

  call lst_AI_Vehicle_Sizes_Name.add("Space Station")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_SPACE_STATION)
  call lst_AI_Vehicle_Sizes_Name.add("Organic Space Station")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_SPACE_STATION)
  call lst_AI_Vehicle_Sizes_Name.add("Crystalline Space Station")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_SPACE_STATION)

  call lst_AI_Vehicle_Sizes_Name.add("Starbase")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_STARBASE)
  call lst_AI_Vehicle_Sizes_Name.add("Organic Starbase")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_STARBASE)
  call lst_AI_Vehicle_Sizes_Name.add("Crystalline Starbase")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_STARBASE)

  call lst_AI_Vehicle_Sizes_Name.add("Colony Ship")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_COLONY_SHIP)
  call lst_AI_Vehicle_Sizes_Name.add("Organic Colony Ship")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_COLONY_SHIP)
  call lst_AI_Vehicle_Sizes_Name.add("Crystalline Colony Ship")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_COLONY_SHIP)

  call lst_AI_Vehicle_Sizes_Name.add("Small Freighter")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_SM_FREIGHTER)
  call lst_AI_Vehicle_Sizes_Name.add("Organic Small Freighter")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_SM_FREIGHTER)
  call lst_AI_Vehicle_Sizes_Name.add("Crystalline Small Freighter")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_SM_FREIGHTER)

  call lst_AI_Vehicle_Sizes_Name.add("Medium Freighter")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_MD_FREIGHTER)
  call lst_AI_Vehicle_Sizes_Name.add("Organic Medium Freighter")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_MD_FREIGHTER)
  call lst_AI_Vehicle_Sizes_Name.add("Crystalline Medium Freighter")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_MD_FREIGHTER)

  call lst_AI_Vehicle_Sizes_Name.add("Large Freighter")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_LG_FREIGHTER)
  call lst_AI_Vehicle_Sizes_Name.add("Organic Large Freighter")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_LG_FREIGHTER)
  call lst_AI_Vehicle_Sizes_Name.add("Crystalline Large Freighter")
  call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_LG_FREIGHTER)

  if (bool_Race_Uses_Troops) then
    // Small Troops
    call lst_AI_Vehicle_Sizes_Name.add("Small Troop")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_SM_TROOP)
    call lst_AI_Vehicle_Sizes_Name.add("Organic Small Troop")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_SM_TROOP)
    call lst_AI_Vehicle_Sizes_Name.add("Crystalline Small Troop")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_SM_TROOP)
    // Medium Troops
    call lst_AI_Vehicle_Sizes_Name.add("Medium Troop")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_MD_TROOP)
    call lst_AI_Vehicle_Sizes_Name.add("Organic Medium Troop")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_MD_TROOP)
    call lst_AI_Vehicle_Sizes_Name.add("Crystalline Medium Troop")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_MD_TROOP)
    // Large Troops
    call lst_AI_Vehicle_Sizes_Name.add("Large Troop")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_LG_TROOP)
    call lst_AI_Vehicle_Sizes_Name.add("Organic Large Troop")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_LG_TROOP)
    call lst_AI_Vehicle_Sizes_Name.add("Crystalline Large Troop")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_LG_TROOP)
  endif

  if (bool_Race_Uses_Fighters) then
    // Small Fighters
    call lst_AI_Vehicle_Sizes_Name.add("Small Fighter")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_SM_FIGHTER)
    call lst_AI_Vehicle_Sizes_Name.add("Organic Small Fighter")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_SM_FIGHTER)
    call lst_AI_Vehicle_Sizes_Name.add("Crystalline Small Fighter")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_SM_FIGHTER)
    // Large Fighters
    call lst_AI_Vehicle_Sizes_Name.add("Large Fighter")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_LG_FIGHTER)
    call lst_AI_Vehicle_Sizes_Name.add("Organic Large Fighter")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_LG_FIGHTER)
    call lst_AI_Vehicle_Sizes_Name.add("Crystalline Large Fighter")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_LG_FIGHTER)
  endif

  if (bool_Race_Uses_Satellites) then
    // Small Satellites
    call lst_AI_Vehicle_Sizes_Name.add("Small Satellite")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_SM_SATELLITE)
    call lst_AI_Vehicle_Sizes_Name.add("Organic Small Satellite")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_SM_SATELLITE)
    call lst_AI_Vehicle_Sizes_Name.add("Crystalline Small Satellite")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_SM_SATELLITE)
    // Large Satellites
    call lst_AI_Vehicle_Sizes_Name.add("Large Satellite")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_LG_SATELLITE)
    call lst_AI_Vehicle_Sizes_Name.add("Organic Large Satellite")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_LG_SATELLITE)
    call lst_AI_Vehicle_Sizes_Name.add("Crystalline Large Satellite")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_LG_SATELLITE)
  endif

  if (bool_Race_Uses_Weapon_Platforms) then
    // Small Weapon Platforms
    call lst_AI_Vehicle_Sizes_Name.add("Small Weapon Platform")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_SM_WEAP_PLATFORM)
    call lst_AI_Vehicle_Sizes_Name.add("Organic Small Weapon Platform")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_SM_WEAP_PLATFORM)
    call lst_AI_Vehicle_Sizes_Name.add("Crystalline Small Weapon Platform")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_SM_WEAP_PLATFORM)
    // Large Weapon Platforms
    call lst_AI_Vehicle_Sizes_Name.add("Large Weapon Platform")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_LG_WEAP_PLATFORM)
    call lst_AI_Vehicle_Sizes_Name.add("Organic Large Weapon Platform")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_LG_WEAP_PLATFORM)
    call lst_AI_Vehicle_Sizes_Name.add("Crystalline Large Weapon Platform")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_LG_WEAP_PLATFORM)
  endif

  if (bool_Race_Uses_Mines) then
    // Small Mines
    call lst_AI_Vehicle_Sizes_Name.add("Small Mine")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_SM_MINE)
    call lst_AI_Vehicle_Sizes_Name.add("Organic Small Mine")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_SM_MINE)
    call lst_AI_Vehicle_Sizes_Name.add("Crystalline Small Mine")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_SM_MINE)
    // Large Mines
    call lst_AI_Vehicle_Sizes_Name.add("Large Mine")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_LG_MINE)
    call lst_AI_Vehicle_Sizes_Name.add("Organic Large Mine")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_LG_MINE)
    call lst_AI_Vehicle_Sizes_Name.add("Crystalline Large Mine")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_LG_MINE)
  endif

  if (bool_Race_Uses_Drones) then
    // Small Drones
    call lst_AI_Vehicle_Sizes_Name.add("Small Drone")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_SM_DRONE)
    call lst_AI_Vehicle_Sizes_Name.add("Organic Small Drone")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_SM_DRONE)
    call lst_AI_Vehicle_Sizes_Name.add("Crystalline Small Drone")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_SM_DRONE)
    // Large Drones
    call lst_AI_Vehicle_Sizes_Name.add("Large Drone")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_LG_DRONE)
    call lst_AI_Vehicle_Sizes_Name.add("Organic Large Drone")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_LG_DRONE)
    call lst_AI_Vehicle_Sizes_Name.add("Crystalline Large Drone")
    call lst_AI_Vehicle_Sizes_AI_Size.add(AI_VEHICLE_SIZE_LG_DRONE)
  endif

end

//------------------------------------------------------------------------
// Set_Race_Design_Types
//------------------------------------------------------------------------
function Set_Race_Design_Types returns boolean
vars
  num_colonies:              long
  num_facilities:            long
  num_wanted:                long
  num_per_facility_base:     long := 1000
  ai_design_type:            string
  ai_vehicle_size:           long
  ai_vehicle_demand:         long
  ai_role:                   long
  ai_state:                  long
  exp_mod_inc:               real := 1.0
  exp_mod_dec:               real := 1.0
  atk_mod_inc:               real := 1.0
  atk_mod_dec:               real := 1.0
  def_mod_inc:               real := 1.0
  def_mod_dec:               real := 1.0
  dis_mod_inc:               real := 1.0
  dis_mod_dec:               real := 1.0
  min_mod_inc:               real := 1.0
  min_mod_dec:               real := 1.0
  org_mod_inc:               real := 1.0
  org_mod_dec:               real := 1.0
  rad_mod_inc:               real := 1.0
  rad_mod_dec:               real := 1.0
  ancient_race_mod:          real := 1.0
  resource_mod:              real := 1.0
  ship_wanted_mod:           real := 1.0
  unit_wanted_mod:           real := 1.0
  max_colonizer_total:       long
  num_planets_rock:          long
  max_colonizer_rock:        long
  num_planets_ice:           long
  max_colonizer_ice:         long
  num_planets_gas:           long
  max_colonizer_gas:         long
  start_combat_mod:          long
  small_atk_ship:            long
  small_def_ship:            long
  medium_atk_ship:           long
  medium_def_ship:           long
  large_atk_ship:            long
  large_def_ship:            long
  small_carrier:             long
  medium_carrier:            long
  large_carrier:             long
  small_base:                long
  large_base:                long
  small_WP:                  long
  large_WP:                  long
  best_freighter:            long
  best_troop:                long
  best_fighter:              long
  best_satellite:            long
  best_mine:                 long
  best_drone:                long
  index:                     long
  atk_ship_ratio:            real := 1.0
  def_ship_ratio:            real := 1.0
  skr_ship_ratio:            real := 1.0
  troop_ratio:               real := 1.0
  light_troop_ratio:         real := 1.0
  fighter_ratio:             real := 1.0
  bomber_ratio:              real := 1.0
  kamikaze_ratio:            real := 1.0
  weapon_platform_ratio:     real := 1.0
  seeker_wp_ratio:           real := 1.0
  satellite_ratio:           real := 1.0
  seeker_sat_ratio:          real := 1.0
  atk_drone_ratio:           real := 1.0
  def_drone_ratio:           real := 1.0
  skr_drone_ratio:           real := 1.0
  colonizer_rock_ratio:      real := 1.0
  colonizer_ice_ratio:       real := 1.0
  colonizer_gas_ratio:       real := 1.0
begin

  // Get our current state
  set ai_state := Sys_Get_AI_State(sys_long_Player_ID)

  // Set our vehicle demand (how much a design is wanted) modifiers
  case ai_state
    AI_STATE_EXPLORE_AND_EXPAND:
      if (bool_Race_Is_Not_Alone) then
        set exp_mod_inc := exp_mod_inc + 2.0
        set exp_mod_dec := exp_mod_dec - 0.5
      else
        set exp_mod_inc := exp_mod_inc + 3.0
        set exp_mod_dec := exp_mod_dec - 1.0
      endif
    AI_STATE_ATTACK:
      set atk_mod_inc := atk_mod_inc + 0.2
      set atk_mod_dec := atk_mod_dec - 0.5
    AI_STATE_DEFEND:
      set def_mod_inc := def_mod_inc + 0.2
      set def_mod_dec := def_mod_dec - 0.2
    AI_STATE_NOT_CONNECTED:
      set dis_mod_inc := dis_mod_inc + 1.0
      set dis_mod_dec := dis_mod_dec - 0.8
  endcase

  // Increase our demand if we have lots of resources
  if (bool_Race_Minerals_High) and (bool_Race_Organics_High) and (bool_Race_Radioactives_High) then
    if (bool_Race_Maintenance_Low) then
      set atk_mod_inc := atk_mod_inc + 1.0
      set def_mod_inc := def_mod_inc + 1.0
    else
      set atk_mod_inc := atk_mod_inc + 0.1
      set def_mod_inc := def_mod_inc + 0.1
    endif
  endif

  // Reduce our wanted numbers if any of our 3 resources is low and maintenance is high
  if (bool_Race_Minerals_Low) or (bool_Race_Organics_Low) or (bool_Race_Radioactives_Low) then
    if (bool_Race_Maintenance_High) then
      // Reduce number wanted by 10%
      set resource_mod := 0.9
    endif
  endif

  // Adjust our resource ship demand modifiers
  if (bool_Race_Minerals_Low) then
    set min_mod_inc := min_mod_inc + 1.0
  endif
  if (bool_Race_Organics_Low) then
    set org_mod_inc := org_mod_inc + 1.0
  endif
  if (bool_Race_Radioactives_Low) then
    set rad_mod_inc := rad_mod_inc + 1.0
  endif

  // Adjust our demand ship/unit wanted modifiers (value set in Set_Race_Resource_Modifiers)
  set ship_wanted_mod := ship_wanted_mod - (lng_Ship_Demand_Reduction_Factor * 0.1)
  set unit_wanted_mod := unit_wanted_mod - (lng_Unit_Demand_Reduction_Factor * 0.1)

  // Modify our demand amounts if we are an ancient race
  if (bool_Race_Is_Ancient_Race) or (lst_AI_Planets_To_Colonize.count() > 5) then
    set ancient_race_mod := ancient_race_mod + 0.5
  endif

  // Get the number of colonies and facilities in our empire
  set num_colonies := Sys_AI_Empire_Stats_Get_Colonies_Statistics(sys_long_Player_ID, COLONIES_STATS_FILTER_NUM_COLONIES)
  set num_facilities := Sys_AI_Empire_Stats_Get_Colonies_Statistics(sys_long_Player_ID, COLONIES_STATS_FILTER_NUM_FACILITIES)
  // Debug output
  call Sys_Debug_Print("Construction", "  - There are " + Sys_Convert_Long_To_String(num_colonies) + " colonies in the Empire")
  call Sys_Debug_Print("Construction", "  - There are " + Sys_Convert_Long_To_String(num_facilities) + " facilities in the Empire")

  // Choose our preferred hull for small combat ships
  If Is_Vehicle_Size_Available("Battleship") then
    set small_atk_ship := AI_VEHICLE_SIZE_DESTROYER
    set small_def_ship := AI_VEHICLE_SIZE_DESTROYER
  else
    set small_atk_ship := AI_VEHICLE_SIZE_FRIGATE
    set small_def_ship := AI_VEHICLE_SIZE_FRIGATE
  endif

  // Choose our preferred hull for medium combat ships
  If Is_Vehicle_Size_Available("Destroyer") then
    set medium_atk_ship := AI_VEHICLE_SIZE_DESTROYER
    set medium_def_ship := AI_VEHICLE_SIZE_DESTROYER
  endif
  If Is_Vehicle_Size_Available("Battleship") then
    set medium_atk_ship := AI_VEHICLE_SIZE_LIGHT_CRUISER
    set medium_def_ship := AI_VEHICLE_SIZE_DESTROYER
  endif
  If Is_Vehicle_Size_Available("Dreadnought") then
    set medium_atk_ship := AI_VEHICLE_SIZE_CRUISER
    set medium_def_ship := AI_VEHICLE_SIZE_LIGHT_CRUISER
  endif

  // Choose our preferred hull for large combat ships
  If Is_Vehicle_Size_Available("Light Cruiser") then
    set large_atk_ship := AI_VEHICLE_SIZE_LIGHT_CRUISER
    set large_def_ship := AI_VEHICLE_SIZE_LIGHT_CRUISER
  endif
  If Is_Vehicle_Size_Available("Cruiser") then
    set large_atk_ship := AI_VEHICLE_SIZE_CRUISER
    set large_def_ship := AI_VEHICLE_SIZE_LIGHT_CRUISER
  endif
  If Is_Vehicle_Size_Available("Battleship") then
    set large_atk_ship := AI_VEHICLE_SIZE_BATTLESHIP
    set large_def_ship := AI_VEHICLE_SIZE_CRUISER
  endif
  If Is_Vehicle_Size_Available("Dreadnought") then
    set large_atk_ship := AI_VEHICLE_SIZE_DREADNOUGHT
    set large_def_ship := AI_VEHICLE_SIZE_BATTLESHIP
  endif

  // Set our hull sizes for Carriers
  If Is_Vehicle_Size_Available("Light Carrier") then
    set small_carrier := AI_VEHICLE_SIZE_LIGHT_CARRIER
  endif
  If Is_Vehicle_Size_Available("Carrier") then
    set medium_carrier := AI_VEHICLE_SIZE_CARRIER
  endif
  If Is_Vehicle_Size_Available("Heavy Carrier") then
    set large_carrier := AI_VEHICLE_SIZE_HEAVY_CARRIER
  endif

  // Designate our best Freighter ship size
  If Is_Vehicle_Size_Available("Large Freighter") then
    set best_freighter := AI_VEHICLE_SIZE_LG_FREIGHTER
  else
    If Is_Vehicle_Size_Available("Medium Freighter") then
      set best_freighter := AI_VEHICLE_SIZE_MD_FREIGHTER
    else
      set best_freighter := AI_VEHICLE_SIZE_SM_FREIGHTER
    endif
  endif

  // Designate our best Space Station size
  If Is_Vehicle_Size_Available("Starbase") then
    set large_base := AI_VEHICLE_SIZE_STARBASE
  else
    set small_base := AI_VEHICLE_SIZE_SPACE_STATION
  endif

  // Designate our best Troop size
  If Is_Vehicle_Size_Available("Large Troop") then
    set best_troop := AI_VEHICLE_SIZE_LG_TROOP
  else
    If Is_Vehicle_Size_Available("Medium Troop") then
      set best_troop := AI_VEHICLE_SIZE_MD_TROOP
    else
      set best_troop := AI_VEHICLE_SIZE_SM_TROOP
    endif
  endif

  // Designate our best Fighter size
  If Is_Vehicle_Size_Available("Large Fighter") then
    set best_fighter := AI_VEHICLE_SIZE_LG_FIGHTER
  else
    set best_fighter := AI_VEHICLE_SIZE_SM_FIGHTER
  endif

  // Designate our best Satellite Size
  If Is_Vehicle_Size_Available("Large Satellite") then
    set best_satellite := AI_VEHICLE_SIZE_LG_SATELLITE
  else
    set best_satellite := AI_VEHICLE_SIZE_SM_SATELLITE
  endif

  // Designate our best Weapon Platform size
  If Is_Vehicle_Size_Available("Large Weapon Platform") then
    set large_WP := AI_VEHICLE_SIZE_LG_WEAP_PLATFORM
    set small_WP := AI_VEHICLE_SIZE_SM_WEAP_PLATFORM
  else
    set small_WP := AI_VEHICLE_SIZE_SM_WEAP_PLATFORM
  endif

  // Designate our best Mine size
  If Is_Vehicle_Size_Available("Large Mine") then
    set best_mine := AI_VEHICLE_SIZE_LG_MINE
  else
    set best_mine := AI_VEHICLE_SIZE_SM_MINE
  endif

  // Designate our best Drone size
  If Is_Vehicle_Size_Available("Large Drone") then
    set best_drone := AI_VEHICLE_SIZE_LG_DRONE
  else
    set best_drone := AI_VEHICLE_SIZE_SM_DRONE
  endif

  // Set modifier ratios to equalize demand for some of our design types

  // Colony Ships
  set num_planets_rock := lst_AI_Planets_To_Colonize_Num_Types.get(1)
  set num_planets_ice := lst_AI_Planets_To_Colonize_Num_Types.get(2)
  set num_planets_gas := lst_AI_Planets_To_Colonize_Num_Types.get(3)

  // Limit the total number of colonizers to build
  if (num_planets_rock > 0) and (num_planets_ice > 0) and (num_planets_gas > 0) and (num_planets_rock + num_planets_ice + num_planets_gas > 15) then
    set max_colonizer_total := 10
  else
    set max_colonizer_total := 5
  endif

  // Adjust our colonizer ratios based on the number of each type of colonizable planet
  if (max_colonizer_total = 10) then
    set colonizer_rock_ratio := num_planets_rock / (num_planets_rock + num_planets_ice + num_planets_gas)
    set colonizer_ice_ratio := num_planets_ice / (num_planets_rock + num_planets_ice + num_planets_gas)
    set colonizer_gas_ratio := num_planets_gas / (num_planets_rock + num_planets_ice + num_planets_gas)
  endif

  // Set the maximum number of each colonizer that we should have at one time
  set max_colonizer_rock := Sys_Trunc(colonizer_rock_ratio * max_colonizer_total)
  set max_colonizer_ice := Sys_Trunc(colonizer_ice_ratio * max_colonizer_total)
  set max_colonizer_gas := Sys_Trunc(colonizer_gas_ratio * max_colonizer_total)

  // Combat ships
  if (lng_AI_Num_Combat_Ships = 0) and (lng_AI_Num_Of_Enemies > 0) then
    set start_combat_mod := 5000
  endif

  // Ratios used to even demand per one
  // Ships
  if (lng_Num_Attack_Ships > 0) then
    set atk_ship_ratio := lng_Num_Attack_Ships / (lng_Num_Attack_Ships + lng_Num_Defense_Ships + lng_Num_Seeker_Ships)
  endif
  if (lng_Num_Defense_Ships > 0) then
    set def_ship_ratio := lng_Num_Defense_Ships / (lng_Num_Attack_Ships + lng_Num_Defense_Ships + lng_Num_Seeker_Ships)
  endif
  if (lng_Num_Seeker_Ships > 0) then
    set skr_ship_ratio := lng_Num_Seeker_Ships / (lng_Num_Attack_Ships + lng_Num_Defense_Ships + lng_Num_Seeker_Ships)
  endif
  // Troops
  if (lng_Num_Troops > 0) then
    set troop_ratio := lng_Num_Troops / (lng_Num_Troops + lng_Num_Light_Troops)
  endif
  if (lng_Num_Light_Troops > 0) then
    set light_troop_ratio := lng_Num_Light_Troops / (lng_Num_Troops + lng_Num_Light_Troops)
  endif
  // Fighters
  if (lng_Num_Fighters > 0) then
    set fighter_ratio := lng_Num_Fighters / (lng_Num_Fighters + lng_Num_Fighter_Bombers + lng_Num_Kamikaze_Fighters)
  endif
  if (lng_Num_Fighter_Bombers > 0) then
    set bomber_ratio := lng_Num_Fighter_Bombers / (lng_Num_Fighters + lng_Num_Fighter_Bombers + lng_Num_Kamikaze_Fighters)
  endif
  if (lng_Num_Kamikaze_Fighters > 0) then
    set kamikaze_ratio := lng_Num_Kamikaze_Fighters / (lng_Num_Fighters + lng_Num_Fighter_Bombers + lng_Num_Kamikaze_Fighters)
  endif
  // Weapon Platforms
  if (lng_Num_Weapon_Platforms > 0) then
    set weapon_platform_ratio := lng_Num_Weapon_Platforms / (lng_Num_Weapon_Platforms + lng_Num_Seeker_WPs)
  endif
  if (lng_Num_Seeker_WPs > 0) then
    set seeker_wp_ratio := lng_Num_Seeker_WPs / (lng_Num_Weapon_Platforms + lng_Num_Seeker_WPs)
  endif
  // Satellites
  if (lng_Num_Satellites > 0) then
    set satellite_ratio := lng_Num_Satellites / (lng_Num_Satellites + lng_Num_Seeker_Sats)
  endif
  if (lng_Num_Seeker_Sats > 0) then
    set seeker_sat_ratio := lng_Num_Seeker_Sats / (lng_Num_Satellites + lng_Num_Seeker_Sats)
  endif
  // Drones
  if (lng_Num_Atk_Drones > 0) then
    set atk_drone_ratio := lng_Num_Atk_Drones / (lng_Num_Atk_Drones + lng_Num_Def_Drones + lng_Num_Seeker_Drones)
  endif
  if (lng_Num_Def_Drones > 0) then
    set def_drone_ratio := lng_Num_Def_Drones / (lng_Num_Atk_Drones + lng_Num_Def_Drones + lng_Num_Seeker_Drones)
  endif
  if (lng_Num_Seeker_Drones > 0) then
    set skr_drone_ratio := lng_Num_Seeker_Drones / (lng_Num_Atk_Drones + lng_Num_Def_Drones + lng_Num_Seeker_Drones)
  endif

  // Set various parameters for our design types
  for index := 1 to 78 do
    set ai_design_type := ""
    set ai_role  := TASK_FORCE_ROLE_CORE

    case index
      1:
        if Is_Component_Available("Rock Colony Module") then
          set ai_design_type         := "Colonizer (Rock)"
          set ai_vehicle_size        := AI_VEHICLE_SIZE_COLONY_SHIP
          set ai_vehicle_demand      := Sys_Trunc(2000 * ancient_race_mod / colonizer_rock_ratio)
          // How many to build?
          set num_wanted             := Sys_Min_Long(num_planets_rock, max_colonizer_rock)
        endif
      2:
        if Is_Component_Available("Ice Colony Module") then
          set ai_design_type         := "Colonizer (Ice)"
          set ai_vehicle_size        := AI_VEHICLE_SIZE_COLONY_SHIP
          set ai_vehicle_demand      := Sys_Trunc(2000 * ancient_race_mod / colonizer_ice_ratio)
          // How many to build?
          set num_wanted             := Sys_Min_Long(num_planets_ice, max_colonizer_ice)
        endif
      3:
        if Is_Component_Available("Gas Giant Colony Module") then
          set ai_design_type         := "Colonizer (Gas)"
          set ai_vehicle_size        := AI_VEHICLE_SIZE_COLONY_SHIP
          set ai_vehicle_demand      := Sys_Trunc(2000 * ancient_race_mod / colonizer_gas_ratio)
          // How many to build?
          set num_wanted             := Sys_Min_Long(num_planets_gas, max_colonizer_gas)
        endif
      4:
        if (large_atk_ship > 0) and (atk_ship_ratio > 0) and (lng_Pct_Large_Ships > 0) then
          set ai_design_type         := "Ship (Attack L)"
          set ai_vehicle_size        := large_atk_ship
          set ai_vehicle_demand      := Sys_Trunc(10000 / atk_ship_ratio / lng_Pct_Large_Ships) + start_combat_mod
          // How many to build?
          if (lng_Num_Attack_Ships < 0) then
            set num_wanted           := Sys_Trunc(lng_Num_Attack_Ships * lng_Pct_Large_Ships / 100) * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Attack_Ships * lng_Pct_Large_Ships / 100 * num_facilities / num_per_facility_base * atk_mod_inc * exp_mod_dec * dis_mod_dec * ship_wanted_mod * resource_mod)
          endif
        endif
      5:
        if (medium_atk_ship > 0) and (atk_ship_ratio > 0) and (lng_Pct_Medium_Ships > 0) then
          set ai_design_type         := "Ship (Attack M)"
          set ai_vehicle_size        := medium_atk_ship
          set ai_vehicle_demand      := Sys_Trunc(10000 / atk_ship_ratio / lng_Pct_Medium_Ships) + start_combat_mod
          // How many to build?
          if (lng_Num_Attack_Ships < 0) then
            set num_wanted           := Sys_Trunc(lng_Num_Attack_Ships * lng_Pct_Medium_Ships / 100) * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Attack_Ships * lng_Pct_Medium_Ships / 100 * num_facilities / num_per_facility_base * atk_mod_inc * exp_mod_dec * dis_mod_dec * ship_wanted_mod * resource_mod)
          endif
        endif
      6:
        if (small_atk_ship > 0) and (atk_ship_ratio > 0) and (lng_Pct_Small_Ships > 0) then
          set ai_design_type         := "Ship (Attack S)"
          set ai_vehicle_size        := small_atk_ship
          set ai_vehicle_demand      := Sys_Trunc(10000 / atk_ship_ratio / lng_Pct_Small_Ships) + start_combat_mod
          // How many to build?
          if (lng_Num_Attack_Ships < 0) then
            set num_wanted           := Sys_Trunc(lng_Num_Attack_Ships * lng_Pct_Small_Ships / 100) * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Attack_Ships * lng_Pct_Small_Ships / 100 * num_facilities / num_per_facility_base * atk_mod_inc * exp_mod_dec * dis_mod_dec * ship_wanted_mod * resource_mod)
          endif
        endif
      7:
        if (large_def_ship > 0) and (def_ship_ratio > 0) and (lng_Pct_Large_Ships > 0) then
          set ai_design_type         := "Ship (Defense L)"
          set ai_vehicle_size        := large_def_ship
          set ai_vehicle_demand      := Sys_Trunc(10000 / def_ship_ratio / lng_Pct_Large_Ships) + start_combat_mod
          // How many to build?
          if (lng_Num_Defense_Ships < 0) then
            set num_wanted           := Sys_Trunc(lng_Num_Defense_Ships * lng_Pct_Large_Ships / 100) * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Defense_Ships * lng_Pct_Large_Ships / 100 * num_facilities / num_per_facility_base * def_mod_inc * exp_mod_dec * dis_mod_dec * ship_wanted_mod * resource_mod)
          endif
        endif
      8:
        if (medium_def_ship > 0) and (def_ship_ratio > 0) and (lng_Pct_Medium_Ships > 0) then
          set ai_design_type         := "Ship (Defense M)"
          set ai_vehicle_size        := medium_def_ship
          set ai_vehicle_demand      := Sys_Trunc(10000 / def_ship_ratio / lng_Pct_Medium_Ships) + start_combat_mod
          // How many to build?
          if (lng_Num_Defense_Ships < 0) then
            set num_wanted           := Sys_Trunc(lng_Num_Defense_Ships * lng_Pct_Medium_Ships / 100) * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Defense_Ships * lng_Pct_Medium_Ships / 100 * num_facilities / num_per_facility_base * def_mod_inc * exp_mod_dec * dis_mod_dec * ship_wanted_mod * resource_mod)
          endif
        endif
      9:
        if (small_def_ship > 0) and (lng_Pct_Small_Ships > 0) then
          set ai_design_type         := "Ship (Defense S)"
          set ai_vehicle_size        := small_def_ship
          set ai_vehicle_demand      := Sys_Trunc(10000 / def_ship_ratio / lng_Pct_Small_Ships) + start_combat_mod
          // How many to build?
          if (lng_Num_Defense_Ships < 0) then
            set num_wanted           := Sys_Trunc(lng_Num_Defense_Ships * lng_Pct_Small_Ships / 100) * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Defense_Ships * lng_Pct_Small_Ships / 100 * num_facilities / num_per_facility_base * def_mod_inc * exp_mod_dec * dis_mod_dec * ship_wanted_mod * resource_mod)
          endif
        endif
     10:
        if (bool_Race_Uses_Seeker_Ships) and (skr_ship_ratio > 0) and (large_atk_ship > 0) and (lng_Pct_Large_Ships > 0) then
          set ai_design_type         := "Ship (Seeker L)"
          set ai_vehicle_size        := large_atk_ship
          set ai_vehicle_demand      := Sys_Trunc(10000 / skr_ship_ratio / lng_Pct_Large_Ships) + start_combat_mod
          // How many to build?
          if (lng_Num_Seeker_Ships < 0) then
            set num_wanted           := Sys_Trunc(lng_Num_Seeker_Ships * lng_Pct_Large_Ships / 100) * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Seeker_Ships * lng_Pct_Large_Ships / 100 * num_facilities / num_per_facility_base * atk_mod_inc * exp_mod_dec * dis_mod_dec * ship_wanted_mod * resource_mod)
          endif
        endif
     11:
        if (bool_Race_Uses_Seeker_Ships) and (skr_ship_ratio > 0) and (medium_atk_ship > 0) and (lng_Pct_Medium_Ships > 0) then
          set ai_design_type         := "Ship (Seeker M)"
          set ai_vehicle_size        := medium_atk_ship
          set ai_vehicle_demand      := Sys_Trunc(10000 / skr_ship_ratio / lng_Pct_Medium_Ships) + start_combat_mod
          // How many to build?
          if (lng_Num_Seeker_Ships < 0) then
            set num_wanted           := Sys_Trunc(lng_Num_Seeker_Ships * lng_Pct_Medium_Ships / 100) * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Seeker_Ships * lng_Pct_Medium_Ships / 100 * num_facilities / num_per_facility_base * atk_mod_inc * exp_mod_dec * dis_mod_dec * ship_wanted_mod * resource_mod)
          endif
        endif
     12:
        if (bool_Race_Uses_Seeker_Ships) and (skr_ship_ratio > 0) and (small_atk_ship > 0) and (lng_Pct_Small_Ships > 0) then
          set ai_design_type         := "Ship (Seeker S)"
          set ai_vehicle_size        := small_atk_ship
          set ai_vehicle_demand      := Sys_Trunc(10000 / skr_ship_ratio / lng_Pct_Small_Ships) + start_combat_mod
          // How many to build?
          if (lng_Num_Seeker_Ships < 0) then
            set num_wanted           := Sys_Trunc(lng_Num_Seeker_Ships * lng_Pct_Small_Ships / 100) * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Seeker_Ships * lng_Pct_Small_Ships / 100 * num_facilities / num_per_facility_base * atk_mod_inc * exp_mod_dec * dis_mod_dec * ship_wanted_mod * resource_mod)
          endif
        endif
     13:
        if Is_Vehicle_Size_Available("Baseship") and (lng_Num_Base_Ships > 0) then
          set ai_design_type         := "Ship (Attack Base)"
          set ai_vehicle_size        := AI_VEHICLE_SIZE_BASESHIP
          set ai_vehicle_demand      := 500
          // How many to build?
          if (lng_Num_Base_Ships < 0) then
            set num_wanted           := lng_Num_Base_Ships * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Base_Ships * num_facilities / num_per_facility_base * atk_mod_inc * exp_mod_dec * dis_mod_dec * ship_wanted_mod * resource_mod)
          endif
        endif
     14:
        if (bool_Race_Is_Not_Alone) then
          set ai_design_type         := "Ship (Point-Defense)"
          set ai_vehicle_size        := Sys_Max_Long(small_atk_ship, medium_atk_ship)
          set ai_vehicle_demand      := 400
          // How many to build?
          if (lng_Num_PD_Ships < 0) then
            set num_wanted           := lng_Num_PD_Ships * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_PD_Ships * num_facilities / num_per_facility_base * def_mod_inc * exp_mod_dec * dis_mod_dec * ship_wanted_mod)
          endif
        endif
     15:
        if (bool_Race_Uses_Scout_Ships) and (lng_Num_Scout_Ships > 0) and (not bool_Are_We_Neutral_Player) then
          set ai_design_type         := "Ship (Scout)"
          set ai_vehicle_size        := AI_VEHICLE_SIZE_FRIGATE
          set ai_vehicle_demand      := 400
          // How many to build?
          if (lng_Num_Scout_Ships < 0) then
            set num_wanted           := lng_Num_Scout_Ships * -1
          else
            set num_wanted           := 2 + Sys_Min_Long(Sys_Trunc(lng_Num_Scout_Ships * num_facilities / num_per_facility_base * exp_mod_inc * def_mod_dec * dis_mod_dec * ship_wanted_mod), lst_AI_Explore_System.count() + lst_AI_Survey_System.count())
          endif
        endif
     16:
        if (bool_Race_Uses_Explorer_Ships) and (lng_Num_Explorer_Ships > 0) and (not bool_Are_We_Neutral_Player) then
          set ai_design_type         := "Ship (Explorer)"
          set ai_vehicle_size        := AI_VEHICLE_SIZE_FRIGATE
          set ai_vehicle_demand      := 400
          // How many to build?
          if (lng_Num_Explorer_Ships < 0) then
            set num_wanted           := lng_Num_Explorer_Ships * -1
          else
            set num_wanted           := 2 + Sys_Min_Long(Sys_Trunc(lng_Num_Explorer_Ships * num_facilities / num_per_facility_base * exp_mod_inc * def_mod_dec * dis_mod_dec * ship_wanted_mod), lst_AI_Explore_System.count() + lst_AI_Survey_System.count())
          endif
        endif
     17:
        if (bool_Race_Is_Not_Alone) and (not bool_Are_We_Neutral_Player) then
          set ai_design_type         := "Ship (Patrol)"
          set ai_vehicle_size        := Sys_Max_Long(small_atk_ship, medium_def_ship)
          set ai_vehicle_demand      := 400
          // How many to build?
          if (lng_Num_Patrol_Ships < 0) then
            set num_wanted           := lng_Num_Patrol_Ships * -1
          else
            set num_wanted           := 2 + Sys_Min_Long(Sys_Trunc(lng_Num_Patrol_Ships * num_facilities / num_per_facility_base * def_mod_inc * exp_mod_dec * dis_mod_dec * ship_wanted_mod), lst_AI_Defense_Location_System.count())
          endif 
        endif
     18:
        if (bool_Race_Uses_Bombardment_Ships) and (lng_Num_Bombardment_Ships > 0) and (bool_Race_Is_Not_Alone) and (not bool_Are_We_Neutral_Player) then
          set ai_design_type         := "Ship (Bombardment)"
          set ai_vehicle_size        := Sys_Max_Long(small_atk_ship, medium_atk_ship)
          set ai_vehicle_demand      := 200
          // How many to build?
          if (lng_Num_Bombardment_Ships < 0) then
            set num_wanted           := lng_Num_Bombardment_Ships * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Bombardment_Ships * num_facilities / num_per_facility_base * atk_mod_inc * def_mod_dec * exp_mod_dec * dis_mod_dec * ship_wanted_mod)
          endif
        endif
     19:
        if (bool_Race_Uses_Boarding_Ships) and (lng_Num_Boarding_Ships > 0) and (bool_Race_Is_Not_Alone) and (not bool_Are_We_Neutral_Player) then
          set ai_design_type         := "Ship (Boarding)"
          set ai_vehicle_size        := Sys_Min_Long(AI_VEHICLE_SIZE_DESTROYER, medium_atk_ship)
          set ai_vehicle_demand      := 400
          // How many to build?
          if (lng_Num_Boarding_Ships < 0) then
            set num_wanted           := lng_Num_Boarding_Ships * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Boarding_Ships * num_facilities / num_per_facility_base * atk_mod_inc * exp_mod_dec * dis_mod_dec * ship_wanted_mod)
          endif
        endif
     20:
        if (bool_Race_Uses_Kamikaze_Ships) and (lng_Num_Kamikaze_Ships > 0) and (bool_Race_Is_Not_Alone) then
          set ai_design_type         := "Ship (Kamikaze)"
          set ai_vehicle_size        := AI_VEHICLE_SIZE_FRIGATE
          set ai_vehicle_demand      := 400
          // How many to build?
          if (lng_Num_Kamikaze_Ships < 0) then
            set num_wanted           := lng_Num_Kamikaze_Ships * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Kamikaze_Ships * num_facilities / num_per_facility_base * atk_mod_dec * def_mod_inc * exp_mod_dec * dis_mod_dec * ship_wanted_mod)
          endif
        endif
     21:
        if (bool_Race_Uses_Fighters) and (bool_Race_Uses_Remote_Fighters) and (large_carrier > 0) and (lng_Pct_Large_Carriers > 0) then
          if Is_Component_Available("Fighter Launcher") then
            set ai_design_type         := "Carrier (Fighter L)"
            set ai_vehicle_size        := large_carrier
            set ai_vehicle_demand      := Sys_Trunc(40000 / lng_Pct_Large_Carriers)
            // How many to build?
            if (lng_Num_Carriers < 0) then
              set num_wanted           := lng_Num_Carriers * -1
            else
              set num_wanted           := Sys_Trunc(lng_Num_Carriers * lng_Pct_Large_Carriers / 100 * num_facilities / num_per_facility_base * atk_mod_inc * exp_mod_dec * dis_mod_dec * ship_wanted_mod)
            endif
          endif
        endif
     22:
        if (bool_Race_Uses_Fighters) and (bool_Race_Uses_Remote_Fighters) and (medium_carrier > 0) and (lng_Pct_Medium_Carriers > 0) then
          if Is_Component_Available("Fighter Launcher") then
            set ai_design_type         := "Carrier (Fighter M)"
            set ai_vehicle_size        := medium_carrier
            set ai_vehicle_demand      := Sys_Trunc(40000 / lng_Pct_Medium_Carriers)
            // How many to build?
            if (lng_Num_Carriers < 0) then
              set num_wanted           := lng_Num_Carriers * -1
            else
              set num_wanted           := Sys_Trunc(lng_Num_Carriers * lng_Pct_Medium_Carriers / 100 * num_facilities / num_per_facility_base * atk_mod_inc * exp_mod_dec * dis_mod_dec * ship_wanted_mod)
            endif
          endif
        endif
     23:
        if (bool_Race_Uses_Fighters) and (bool_Race_Uses_Remote_Fighters) and (small_carrier > 0) and (lng_Pct_Small_Carriers > 0) then
          if Is_Component_Available("Fighter Launcher") then
            set ai_design_type         := "Carrier (Fighter S)"
            set ai_vehicle_size        := small_carrier
            set ai_vehicle_demand      := Sys_Trunc(40000 / lng_Pct_Small_Carriers)
            // How many to build?
            if (lng_Num_Carriers < 0) then
              set num_wanted           := lng_Num_Carriers * -1
            else
              set num_wanted           := Sys_Trunc(lng_Num_Carriers * lng_Pct_Small_Carriers / 100 * num_facilities / num_per_facility_base * atk_mod_inc * exp_mod_dec * dis_mod_dec * ship_wanted_mod)
            endif
          endif
        endif
     24:
        if (bool_Race_Uses_Drones) and (bool_Race_Uses_Remote_Drones) and (large_carrier > 0) and (lng_Pct_Large_Carriers > 0) then
          if Is_Component_Available("Drone Launcher") then
            set ai_design_type         := "Carrier (Drone L)"
            set ai_vehicle_size        := large_carrier
            set ai_vehicle_demand      := SYs_Trunc(40000 / lng_Pct_Large_Carriers)
            // How many to build?
            if (lng_Num_Drone_Carriers < 0) then
              set num_wanted           := lng_Num_Drone_Carriers * -1
            else
              set num_wanted           := Sys_Trunc(lng_Num_Drone_Carriers * lng_Pct_Small_Carriers / 100 * num_facilities / num_per_facility_base * atk_mod_inc * exp_mod_dec * dis_mod_dec * ship_wanted_mod)
            endif
          endif
        endif
     25:
        if (bool_Race_Uses_Drones) and (bool_Race_Uses_Remote_Drones) and (medium_carrier > 0) and (lng_Pct_Medium_Carriers > 0) then
          if Is_Component_Available("Drone Launcher") then
            set ai_design_type         := "Carrier (Drone M)"
            set ai_vehicle_size        := medium_carrier
            set ai_vehicle_demand      := SYs_Trunc(40000 / lng_Pct_Medium_Carriers)
            // How many to build?
            if (lng_Num_Drone_Carriers < 0) then
              set num_wanted           := lng_Num_Drone_Carriers * -1
            else
              set num_wanted           := Sys_Trunc(lng_Num_Drone_Carriers * lng_Pct_Medium_Carriers / 100 * num_facilities / num_per_facility_base * atk_mod_inc * exp_mod_dec * dis_mod_dec * ship_wanted_mod)
            endif
          endif
        endif
     26:
        if (bool_Race_Uses_Drones) and (bool_Race_Uses_Remote_Drones) and (small_carrier > 0) and (lng_Pct_Small_Carriers > 0) then
          if Is_Component_Available("Drone Launcher") then
            set ai_design_type         := "Carrier (Drone S)"
            set ai_vehicle_size        := small_carrier
            set ai_vehicle_demand      := SYs_Trunc(40000 / lng_Pct_Small_Carriers)
            // How many to build?
            if (lng_Num_Drone_Carriers < 0) then
              set num_wanted           := lng_Num_Drone_Carriers * -1
            else
              set num_wanted           := Sys_Trunc(lng_Num_Drone_Carriers * lng_Pct_Small_Carriers / 100 * num_facilities / num_per_facility_base * atk_mod_inc * exp_mod_dec * dis_mod_dec * ship_wanted_mod)
            endif
          endif
        endif
     27:
        If Is_Vehicle_Size_Available("Medium Freighter") then
          set ai_design_type         := "Ship (Space Yard)"
          set ai_vehicle_size        := AI_VEHICLE_SIZE_MD_FREIGHTER
          set ai_vehicle_demand      := 1000
          // How many to build?
          if (lng_Num_Space_Yard_Ships < 0) then
            set num_wanted           := lng_Num_Space_Yard_Ships * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Space_Yard_Ships * num_facilities / num_per_facility_base * exp_mod_dec * def_mod_dec * dis_mod_dec * ship_wanted_mod)
          endif
        endif
     28:
        if (num_facilities > 50) and Is_Component_Available("Repair Bay") then
          set ai_design_type         := "Ship (Repair)"
          set ai_vehicle_size        := Sys_Min_Long(best_freighter, AI_VEHICLE_SIZE_MD_FREIGHTER)
          set ai_vehicle_demand      := 800
          // How many to build?
          if (lng_Num_Repair_Ships < 0) then
            set num_wanted           := lng_Num_Repair_Ships * -1
          else
            set num_wanted           := 1 + Sys_Trunc(lng_Num_Repair_Ships * num_facilities / num_per_facility_base * exp_mod_dec * dis_mod_dec * ship_wanted_mod)
          endif
        endif
     29:
        if (num_facilities > 50) and (bool_Race_Uses_Troops) and (bool_Race_Is_Not_Alone) and (not bool_Are_We_Neutral_Player) then
          set ai_design_type         := "Transport (Troop)"
          set ai_vehicle_size        := Sys_Min_Long(best_freighter, AI_VEHICLE_SIZE_MD_FREIGHTER)
          set ai_vehicle_demand      := 800
          // How many to build?
          if (lng_Num_Troop_Transports < 0) then
            set num_wanted           := lng_Num_Troop_Transports * -1
          else
            set num_wanted           := 1 + Sys_Trunc(lng_Num_Troop_Transports * num_facilities / num_per_facility_base * atk_mod_inc * def_mod_dec * exp_mod_dec * dis_mod_dec * ship_wanted_mod)
          endif
        endif
     30:
        if (num_facilities > 50) and (bool_Race_Is_Not_Alone) and (not bool_Are_We_Neutral_Player) then
          set ai_design_type         := "Transport (Supply)"
          set ai_vehicle_size        := best_freighter
          set ai_vehicle_demand      := 800
          // How many to build?
          if (lng_Num_Supply_Transports < 0) then
            set num_wanted           := lng_Num_Supply_Transports * -1
          else
            set num_wanted           := 1 + Sys_Trunc(lng_Num_Supply_Transports * num_facilities / num_per_facility_base * def_mod_dec * dis_mod_dec * ship_wanted_mod)
          endif
        endif
     31:
        if (num_facilities > 50) then
          set ai_design_type         := "Transport (Cargo)"
          set ai_vehicle_size        := best_freighter
          set ai_vehicle_demand      := 600
          // How many to build?
          if (lng_Num_Cargo_Transports < 0) then
            set num_wanted           := lng_Num_Cargo_Transports * -1
          else
            set num_wanted           := 1 + Sys_Trunc(lng_Num_Cargo_Transports * num_facilities / num_per_facility_base * dis_mod_dec * ship_wanted_mod)
          endif
        endif
     32:
        if (num_colonies > 5) then
          set ai_design_type         := "Transport (Population)"
          set ai_vehicle_size        := AI_VEHICLE_SIZE_SM_FREIGHTER
          set ai_vehicle_demand      := 600
          // How many to build?
          if (lng_Num_Pop_Transports < 0) then
            set num_wanted           := lng_Num_Pop_Transports * -1
          else
            set num_wanted           := 1 + Sys_Trunc(lng_Num_Pop_Transports * num_facilities / num_per_facility_base * def_mod_dec * dis_mod_dec * ship_wanted_mod)
          endif
        endif
     33:
        if (num_facilities > 50) and (bool_Race_Uses_Satellites) and (bool_Race_Uses_Remote_Satellites) and (bool_Race_Is_Not_Alone) then
          if Is_Component_Available("Satellite Launcher") then
            set ai_design_type         := "Ship (Satellite Launcher)"
            set ai_vehicle_size        := Sys_Min_Long(best_freighter, AI_VEHICLE_SIZE_MD_FREIGHTER)
            set ai_vehicle_demand      := 600
            // How many to build?
            if (lng_Num_Sat_Layers < 0) then
              set num_wanted           := lng_Num_Sat_Layers * -1
            else
              set num_wanted           := 1 + Sys_Trunc(lng_Num_Sat_Layers * num_facilities / num_per_facility_base * def_mod_inc * exp_mod_dec * dis_mod_dec * ship_wanted_mod)
            endif
          endif
        endif
     34:
        if (num_facilities > 50) and (bool_Race_Uses_Mines) and (bool_Race_Uses_Remote_Mines) and (bool_Race_Is_Not_Alone) then 
          if Is_Component_Available("Mine Layer") then
            set ai_design_type         := "Ship (Mine Layer)"
            set ai_vehicle_size        := Sys_Min_Long(best_freighter, AI_VEHICLE_SIZE_MD_FREIGHTER)
            set ai_vehicle_demand      := 600
            // How many to build?
            if (lng_Num_Mine_Layers < 0) then
              set num_wanted           := lng_Num_Mine_Layers * -1
            else
              set num_wanted           := 1 + Sys_Trunc(lng_Num_Mine_Layers * num_facilities / num_per_facility_base * def_mod_inc * exp_mod_dec * dis_mod_dec * ship_wanted_mod)
            endif
          endif
        endif
     35:
        if (num_facilities > 50) and (bool_Race_Is_Not_Alone) then
          if Is_Component_Available("Mine Sweeper") then
            set ai_design_type         := "Ship (Mine Sweeper)"
            set ai_vehicle_size        := best_freighter
            set ai_vehicle_demand      := 600
            // How many to build?
            if (lng_Num_Mine_Sweepers < 0) then
              set num_wanted           := lng_Num_Mine_Sweepers * -1
            else
              set num_wanted           := 1 + Sys_Trunc(lng_Num_Mine_Sweepers * num_facilities / num_per_facility_base * atk_mod_inc * def_mod_dec * exp_mod_dec * dis_mod_dec * ship_wanted_mod)
            endif
          endif
        endif
     36:
        if Is_Component_Available("Medical Bay") then
          set ai_design_type         := "Ship (Medical)"
          set ai_vehicle_size        := AI_VEHICLE_SIZE_FRIGATE
          set ai_vehicle_demand      := 2000
          set num_wanted             := Sys_Min_Long(lst_AI_Our_Plagued_Colonies.count(), 5)
        endif
     37:
        if (bool_Race_Uses_Plague_Ships) and (bool_Race_Is_Not_Alone) then
          set ai_design_type         := "Ship (Plague)"
          set ai_vehicle_size        := small_atk_ship
          set ai_vehicle_demand      := 800
          set num_wanted             := Sys_Trunc(lng_Num_Plague_Ships * num_facilities / num_per_facility_base * atk_mod_inc * def_mod_dec * exp_mod_dec * dis_mod_dec * ship_wanted_mod)
        endif
     38:
        if (bool_Race_Uses_Remote_Mining_Ships) then
          if Is_Component_Available("Robo-Miners") then
            set ai_design_type         := "Ship (Remote Mining)"
            set ai_vehicle_size        := best_freighter
            set ai_vehicle_demand      := 400
            // How many to build?
            if (lng_Num_Mining_Ships < 0) then
              set num_wanted           := lng_Num_Mining_Ships * -1
            else
              set num_wanted           := Sys_Min_Long(Sys_Trunc(lng_Num_Mining_Ships * num_facilities / num_per_facility_base * min_mod_inc * min_mod_dec), Sys_Divide_Long(lst_AI_Asteroid_Fields_For_Resources.count(), 2))
            endif
          endif
        endif
     39:
        if (bool_Race_Uses_Remote_Farming_Ships) then
          if Is_Component_Available("Robo-Farmers")then
            set ai_design_type         := "Ship (Remote Farming)"
            set ai_vehicle_size        := best_freighter
            set ai_vehicle_demand      := 400
            // How many to build?
            if (lng_Num_Farming_Ships < 0) then
              set num_wanted           := lng_Num_Farming_Ships * -1
            else
              set num_wanted           := Sys_Min_Long(Sys_Trunc(lng_Num_Farming_Ships * num_facilities / num_per_facility_base * org_mod_inc * org_mod_dec), Sys_Divide_Long(lst_AI_Asteroid_Fields_For_Resources.count(), 3))
            endif
          endif
        endif
     40:
        if (bool_Race_Uses_Remote_Refining_Ships) then
          if Is_Component_Available("Robo-Extractors") then
            set ai_design_type         := "Ship (Remote Refining)"
            set ai_vehicle_size        := best_freighter
            set ai_vehicle_demand      := 400
            // How many to build?
            if (lng_Num_Refining_Ships < 0) then
              set num_wanted           := lng_Num_Refining_Ships * -1
            else
              set num_wanted           := Sys_Min_Long(Sys_Trunc(lng_Num_Refining_Ships * num_facilities / num_per_facility_base * rad_mod_inc * rad_mod_dec), Sys_Divide_Long(lst_AI_Asteroid_Fields_For_Resources.count(), 3))
            endif
          endif
        endif
     41:
        if (large_base > 0) and (bool_Race_Is_Not_Alone) and (lng_Pct_Large_Bases > 0) then
          set ai_design_type         := "Base (Defense L)"
          set ai_vehicle_size        := large_base
          set ai_vehicle_demand      := Sys_Trunc(50000 / lng_Pct_Large_Bases)
          // How many to build?
          if (lng_Num_Defense_Bases < 0) then
            set num_wanted           := lng_Num_Defense_Bases * -1
          else
            set num_wanted           := 1 + Sys_Trunc(lng_Num_Defense_Bases * lng_Pct_Large_Bases / 100 * num_facilities / num_per_facility_base * def_mod_inc * exp_mod_dec * dis_mod_dec * ship_wanted_mod)
          endif
        endif
     42:
        if (small_base > 0) and (bool_Race_Is_Not_Alone) and (lng_Pct_Small_Bases > 0) then
          set ai_design_type         := "Base (Defense S)"
          set ai_vehicle_size        := small_base
          set ai_vehicle_demand      := Sys_Trunc(50000 / lng_Pct_Small_Bases)
          // How many to build?
          if (lng_Num_Defense_Bases < 0) then
            set num_wanted           := lng_Num_Defense_Bases * -1
          else
            set num_wanted           := 1 + Sys_Trunc(lng_Num_Defense_Bases * lng_Pct_Small_Bases / 100 * num_facilities / num_per_facility_base * def_mod_inc * exp_mod_dec * dis_mod_dec * ship_wanted_mod)
          endif
        endif
     43:
        set ai_design_type         := "Base (Space Yard)"
        set ai_vehicle_size        := AI_VEHICLE_SIZE_SPACE_STATION
        set ai_vehicle_demand      := 1000
        // How many to build?
        if (lng_Num_Base_Space_Yards < 0) then
          set num_wanted           := lng_Num_Base_Space_Yards * -1
        else
          set num_wanted           := 1 + Sys_Trunc(lng_Num_Base_Space_Yards * num_facilities / num_per_facility_base * atk_mod_inc * exp_mod_inc * dis_mod_dec * ship_wanted_mod)
        endif
     44:
        if (bool_Race_Uses_Troops) and (troop_ratio > 0) then
          set ai_design_type         := "Troop"
          set ai_vehicle_size        := best_troop
          set ai_vehicle_demand      := Sys_Trunc(3 / troop_ratio)
          // How many to build?
          if (lng_Num_Troops < 0) then
            set num_wanted           := lng_Num_Troops * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Troops * num_facilities / num_per_facility_base * exp_mod_dec * dis_mod_dec * unit_wanted_mod)
          endif
        endif
     45:
        if (bool_Race_Uses_Troops) and (light_troop_ratio > 0) and (best_troop > AI_VEHICLE_SIZE_SM_TROOP) then
          set ai_design_type         := "Troop (Light)"
          set ai_vehicle_size        := AI_VEHICLE_SIZE_SM_TROOP
          set ai_vehicle_demand      := Sys_Trunc(3 / light_troop_ratio)
          set num_wanted             := Sys_Trunc(lng_Num_Light_Troops * num_facilities / num_per_facility_base * def_mod_inc * exp_mod_dec * dis_mod_dec * unit_wanted_mod)
        endif
     46:
        if (bool_Race_Uses_Troops) and (best_troop >= AI_VEHICLE_SIZE_LG_TROOP) then
          set ai_design_type         := "Troop (Heavy)"
          set ai_vehicle_size        := AI_VEHICLE_SIZE_LG_TROOP
          set ai_vehicle_demand      := 20
          set num_wanted             := Sys_Trunc(lng_Num_Heavy_Troops * num_facilities / num_per_facility_base * exp_mod_dec * dis_mod_dec * unit_wanted_mod)
        endif
     47:
        if (bool_Race_Uses_Fighters) and (fighter_ratio > 0) then
          set ai_design_type         := "Fighter"
          set ai_vehicle_size        := best_fighter
          set ai_role                := TASK_FORCE_ROLE_CORE
          set ai_vehicle_demand      := Sys_Trunc(4 / fighter_ratio)
          // How many to build?
          if (lng_Num_Fighters < 0) then
            set num_wanted           := lng_Num_Fighters * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Fighters * num_facilities / num_per_facility_base * def_mod_dec * exp_mod_dec * dis_mod_dec * unit_wanted_mod * resource_mod)
          endif
        endif
     48:
        if (bool_Race_Uses_Fighters) and (bomber_ratio > 0) then
          set ai_design_type         := "Fighter (Bomber)"
          set ai_vehicle_size        := best_fighter
          set ai_role                := TASK_FORCE_ROLE_CORE
          set ai_vehicle_demand      := Sys_Trunc(4 / bomber_ratio)
          // How many to build?
          if (lng_Num_Fighter_Bombers < 0) then
            set num_wanted           := lng_Num_Fighter_Bombers * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Fighter_Bombers * num_facilities / num_per_facility_base * def_mod_dec * exp_mod_dec * dis_mod_dec * unit_wanted_mod * resource_mod)
          endif
        endif
     49:
        if (bool_Race_Uses_Fighters) and (bool_Race_Uses_Kamikaze_Ships) and (bool_Race_Is_Not_Alone) then
          set ai_design_type         := "Fighter (Kamikaze)"
          set ai_vehicle_size        := AI_VEHICLE_SIZE_SM_FIGHTER
          set ai_role                := TASK_FORCE_ROLE_CORE
          set ai_vehicle_demand      := 10
          // How many to build?
          if (lng_Num_Kamikaze_Fighters < 0) then
            set num_wanted           := lng_Num_Kamikaze_Fighters * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Kamikaze_Fighters * num_facilities / num_per_facility_base * def_mod_inc * atk_mod_dec * exp_mod_dec * dis_mod_dec * unit_wanted_mod)
          endif
        endif
     50:
        if (bool_Race_Uses_Weapon_Platforms) and (large_WP > 0) and (lng_Pct_Large_WPs > 0) and (weapon_platform_ratio > 0) then
          set ai_design_type         := "Weapon Platform (L)"
          set ai_vehicle_size        := large_WP
          set ai_vehicle_demand      := Sys_Trunc(10000 / weapon_platform_ratio / lng_Pct_Large_WPs)
          // How many to build?
          if (lng_Num_Weapon_Platforms < 0) then
            set num_wanted           := Sys_Trunc(lng_Num_Weapon_Platforms * lng_Pct_Large_WPs / 100) * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Weapon_Platforms * lng_Pct_Large_WPs / 100 * num_facilities / num_per_facility_base * def_mod_inc * exp_mod_dec * dis_mod_dec * unit_wanted_mod)
          endif
        endif
     51:
        if (bool_Race_Uses_Weapon_Platforms) and (small_WP > 0) and (lng_Pct_Small_WPs > 0) and (weapon_platform_ratio > 0) then
          set ai_design_type         := "Weapon Platform (S)"
          set ai_vehicle_size        := small_WP
          set ai_vehicle_demand      := Sys_Trunc(10000 / weapon_platform_ratio / lng_Pct_Small_WPs)
          // How many to build?
          if (lng_Num_Weapon_Platforms < 0) then
            set num_wanted           := Sys_Trunc(lng_Num_Weapon_Platforms * lng_Pct_Small_WPs / 100) * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Weapon_Platforms * lng_Pct_Small_WPs / 100 * num_facilities / num_per_facility_base * def_mod_inc * exp_mod_dec * dis_mod_dec * unit_wanted_mod)
          endif
        endif
     52:
        if (bool_Race_Uses_Weapon_Platforms) and (bool_Race_Uses_Seeker_Ships) and (large_WP > 0) and (lng_Pct_Large_WPs > 0) and (seeker_wp_ratio > 0) then
          set ai_design_type         := "Weapon Platform (Seeker L)"
          set ai_vehicle_size        := large_WP
          set ai_vehicle_demand      := Sys_Trunc(10000 / seeker_wp_ratio / lng_Pct_Large_WPs)
          // How many to build?
          if (lng_Num_Seeker_WPs < 0) then
            set num_wanted           := Sys_Trunc(lng_Num_Seeker_WPs * lng_Pct_Large_WPs / 100) * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Seeker_WPs * lng_Pct_Large_WPs / 100 * num_facilities / num_per_facility_base * def_mod_inc * exp_mod_dec * dis_mod_dec * unit_wanted_mod)
          endif
        endif
     53:
        if (bool_Race_Uses_Weapon_Platforms) and (bool_Race_Uses_Seeker_Ships) and (small_WP > 0) and (lng_Pct_Small_WPs > 0) and (seeker_wp_ratio > 0)  then
          set ai_design_type         := "Weapon Platform (Seeker S)"
          set ai_vehicle_size        := small_WP
          set ai_vehicle_demand      := Sys_Trunc(10000 / seeker_wp_ratio / lng_Pct_Small_WPs)
          // How many to build?
          if (lng_Num_Seeker_WPs < 0) then
            set num_wanted           := Sys_Trunc(lng_Num_Seeker_WPs * lng_Pct_Small_WPs / 100) * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Seeker_WPs * lng_Pct_Small_WPs / 100 * num_facilities / num_per_facility_base * def_mod_inc * exp_mod_dec * dis_mod_dec * unit_wanted_mod)
          endif
        endif
     54:
        if (bool_Race_Uses_Satellites) and (lng_Num_Satellites > 0) and (satellite_ratio > 0) then
          set ai_design_type         := "Satellite"
          set ai_vehicle_size        := best_satellite
          set ai_vehicle_demand      := Sys_Trunc(20 / satellite_ratio)
          // How many to build?
          if (lng_Num_Satellites < 0) then
            set num_wanted           := lng_Num_Satellites * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Satellites * num_facilities / num_per_facility_base * def_mod_inc * exp_mod_dec * dis_mod_dec * unit_wanted_mod)
          endif
        endif
     55:
        if (bool_Race_Uses_Satellites) then
          set ai_design_type         := "Satellite (Point-Defense)"
          set ai_vehicle_size        := AI_VEHICLE_SIZE_SM_SATELLITE
          set ai_vehicle_demand      := 50
          // How many to build?
          if (lng_Num_PD_Sats < 0) then
            set num_wanted           := lng_Num_PD_Sats * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_PD_Sats * num_facilities / num_per_facility_base * def_mod_inc * exp_mod_dec * dis_mod_dec * unit_wanted_mod)
          endif
        endif
     56:
        if (bool_Race_Uses_Satellites) and (lng_Num_Seeker_Sats > 0) and (best_satellite = AI_VEHICLE_SIZE_LG_SATELLITE) and (seeker_sat_ratio > 0) then
          set ai_design_type         := "Satellite (Seeker)"
          set ai_vehicle_size        := best_satellite
          set ai_vehicle_demand      := Sys_Trunc(20 / seeker_sat_ratio)
          // How many to build?
          if (lng_Num_Seeker_Sats < 0) then
            set num_wanted           := lng_Num_Seeker_Sats * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Seeker_Sats * num_facilities / num_per_facility_base * def_mod_inc * exp_mod_dec * dis_mod_dec * unit_wanted_mod)
          endif
        endif
     57:
        if (bool_Race_Uses_Satellites) and (lng_Num_Recon_Sats > 0) and (bool_Race_Is_Not_Alone) then
          set ai_design_type         := "Satellite (Recon)"
          set ai_vehicle_size        := best_satellite
          set ai_vehicle_demand      := 50
          // How many to build?
          if (lng_Num_Recon_Sats < 0) then
            set num_wanted           := lng_Num_Recon_Sats * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Recon_Sats * num_facilities / num_per_facility_base * dis_mod_dec * unit_wanted_mod)
          endif
        endif
     58:
        if (bool_Race_Uses_Satellites) and (lng_Num_Repair_Sats > 0) and (Is_Component_Available("Repair Pod")) then
          set ai_design_type         := "Satellite (Repair)"
          set ai_vehicle_size        := best_satellite
          set ai_vehicle_demand      := 50
          // How many to build?
          if (lng_Num_Repair_Sats < 0) then
            set num_wanted           := lng_Num_Repair_Sats * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Repair_Sats * num_facilities / num_per_facility_base * dis_mod_dec * unit_wanted_mod)
          endif
        endif
     59:
        if (bool_Race_Uses_Mines) and Is_Vehicle_Size_Available("Small Mine") and (bool_Race_Is_Not_Alone) then
          set ai_design_type         := "Mine"
          set ai_vehicle_size        := best_mine
          set ai_vehicle_demand      := 2
          // How many to build?
          if (lng_Num_Mines < 0) then
            set num_wanted           := lng_Num_Mines * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Mines * num_facilities / num_per_facility_base * def_mod_inc * exp_mod_dec * dis_mod_dec * unit_wanted_mod)
          endif
        endif
     61:
        if (bool_Race_Uses_Drones) and (lng_Num_Atk_Drones > 0) and (best_drone > 0) and (atk_drone_ratio > 0) then
          set ai_design_type         := "Drone (Attack)"
          set ai_vehicle_size        := best_drone
          set ai_vehicle_demand      := Sys_Trunc(40 / atk_drone_ratio)
          // How many to build?
          if (lng_Num_Atk_Drones < 0) then
            set num_wanted           := lng_Num_Atk_Drones * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Atk_Drones * num_facilities / num_per_facility_base * atk_mod_inc * def_mod_dec * exp_mod_dec * dis_mod_dec * unit_wanted_mod)
          endif
        endif
     62:
        if (bool_Race_Uses_Drones) and (lng_Num_Def_Drones > 0) and (best_drone > 0) and (def_drone_ratio > 0) then
          set ai_design_type         := "Drone (Defense)"
          set ai_vehicle_size        := best_drone
          set ai_vehicle_demand      := Sys_Trunc(40 / def_drone_ratio)
          // How many to build?
          if (lng_Num_Atk_Drones < 0) then
            set num_wanted           := lng_Num_Atk_Drones * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Def_Drones * num_facilities / num_per_facility_base * def_mod_inc * atk_mod_dec * exp_mod_dec * dis_mod_dec * unit_wanted_mod)
          endif
        endif
     63:
        if (bool_Race_Uses_Drones) and (lng_Num_Seeker_Drones > 0) and (best_drone > 0) and (skr_drone_ratio > 0) then
          set ai_design_type         := "Drone (Seeker)"
          set ai_vehicle_size        := best_drone
          set ai_vehicle_demand      := Sys_Trunc(40 / skr_drone_ratio)
          // How many to build?
          if (lng_Num_Seeker_Drones < 0) then
            set num_wanted           := lng_Num_Seeker_Drones * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Seeker_Drones * num_facilities / num_per_facility_base * def_mod_inc * atk_mod_dec * exp_mod_dec * dis_mod_dec * unit_wanted_mod)
          endif
        endif
     64:
        if (bool_Race_Uses_Drones) and (lng_Num_Kamikaze_Drones > 0) and (best_drone > 0) then
          set ai_design_type         := "Drone (Kamikaze)"
          set ai_vehicle_size        := AI_VEHICLE_SIZE_SM_DRONE
          set ai_vehicle_demand      := 40
          // How many to build?
          if (lng_Num_Kamikaze_Drones < 0) then
            set num_wanted           := lng_Num_Kamikaze_Drones * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Kamikaze_Drones * num_facilities / num_per_facility_base * def_mod_inc * atk_mod_dec * exp_mod_dec * dis_mod_dec * unit_wanted_mod)
          endif
        endif
     65:
        if (bool_Race_Uses_Drones) and (lng_Num_Bombardment_Drones > 0) and (best_drone > 0) then
          set ai_design_type         := "Drone (Bombardment)"
          set ai_vehicle_size        := best_drone
          set ai_vehicle_demand      := 60
          // How many to build?
          if (lng_Num_Bombardment_Drones < 0) then
            set num_wanted           := lng_Num_Bombardment_Drones * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Bombardment_Drones * num_facilities / num_per_facility_base * def_mod_inc * atk_mod_dec * exp_mod_dec * dis_mod_dec * unit_wanted_mod)
          endif
        endif
     66:
        if (bool_Race_Uses_Drones) and (lng_Num_Repair_Drones > 0) and (best_drone > 0) and (Is_Component_Available("Repair Pod")) then
          set ai_design_type         := "Drone (Repair)"
          set ai_vehicle_size        := best_drone
          set ai_vehicle_demand      := 60
          // How many to build?
          if (lng_Num_Repair_Drones < 0) then
            set num_wanted           := lng_Num_Repair_Drones * -1
          else
            set num_wanted           := Sys_Trunc(lng_Num_Repair_Drones * num_facilities / num_per_facility_base * def_mod_inc * atk_mod_dec * exp_mod_dec * dis_mod_dec * unit_wanted_mod)
          endif
        endif
     67:
        if (bool_Race_Uses_Stellar_Manipulation_Ships) and (not bool_Are_We_Neutral_Player) then
          if Is_Component_Available("Gravitational Quantum Resonator") then
            set ai_design_type         := "Ship (Warp Point Opener)"
            set ai_vehicle_size        := AI_VEHICLE_SIZE_CRUISER
            set ai_vehicle_demand      := 1000
            set num_wanted             := Sys_Max_Long(1, Sys_Trunc(lng_Num_WP_Openers * num_facilities / num_per_facility_base * dis_mod_inc * ship_wanted_mod))
            // Do we need a warp point opener?
            if (bool_Race_Limited_Connectivity) or (ai_state = AI_STATE_NOT_CONNECTED) then
              set ai_vehicle_demand    := 5000
              set num_wanted           := 1
            endif
          endif
        endif
     68:
        if (bool_Race_Uses_Stellar_Manipulation_Ships) and (bool_Race_Is_Not_Alone) then
          if Is_Component_Available("Gravitational Condenser") then
            set ai_design_type         := "Ship (Warp Point Closer)"
            set ai_vehicle_size        := AI_VEHICLE_SIZE_CRUISER
            set ai_vehicle_demand      := 1000
            // How many to build?
            set num_wanted             := Sys_Max_Long(1, Sys_Trunc(lng_Num_WP_Closers * num_facilities / num_per_facility_base * ship_wanted_mod))
          endif
        endif
     69:
        if (bool_Race_Uses_Stellar_Manipulation_Ships) then
          if Is_Component_Available("Matter Gravity Sphere") then
            set ai_design_type         := "Ship (Planet Creator)"
            set ai_vehicle_size        := AI_VEHICLE_SIZE_CRUISER
            set ai_vehicle_demand      := 1000
            // How many to build?
            set num_wanted             := Sys_Trunc(lng_Num_Planet_Creators * num_facilities / num_per_facility_base * ship_wanted_mod)
          endif
        endif
     70:
        if (bool_Race_Uses_Evil_Stellar_Manipulation_Ships) and (not bool_Are_We_Neutral_Player) and (bool_Race_Is_Not_Alone) then
          if Is_Component_Available("Tectonic Bomb") then
            set ai_design_type         := "Ship (Planet Destroyer)"
            set ai_vehicle_size        := AI_VEHICLE_SIZE_CRUISER
            set ai_vehicle_demand      := 500
            // How many to build?
            set num_wanted             := Sys_Trunc(num_facilities / num_per_facility_base * ship_wanted_mod)
          endif
        endif
     71:
        if (bool_Race_Uses_Stellar_Manipulation_Ships) and (not bool_Are_We_Neutral_Player) then
          if Is_Component_Available("Stellar Plasma Sphere") then
            set ai_design_type         := "Ship (Star Creator)"
            set ai_vehicle_size        := AI_VEHICLE_SIZE_CRUISER
            set ai_vehicle_demand      := 500
            // How many to build?
            set num_wanted             := 0
          endif
        endif
     72:
        if (bool_Race_Uses_Evil_Stellar_Manipulation_Ships) and (not bool_Are_We_Neutral_Player) and (bool_Race_Is_Not_Alone) then
          if Is_Component_Available("Stellar Nucleonic Torpedo") then
            set ai_design_type         := "Ship (Star Destroyer)"
            set ai_vehicle_size        := AI_VEHICLE_SIZE_CRUISER
            set ai_vehicle_demand      := 500
            // How many to build?
            set num_wanted             := Sys_Trunc(num_facilities / num_per_facility_base * ship_wanted_mod)
          endif
        endif
     73:
        if (bool_Race_Uses_Evil_Stellar_Manipulation_Ships) and (not bool_Are_We_Neutral_Player) and (bool_Race_Is_Not_Alone) then
          if Is_Component_Available("Ionic Concussion Blaster") then
            set ai_design_type         := "Ship (Storm Creator)"
            set ai_vehicle_size        := AI_VEHICLE_SIZE_CRUISER
            set ai_vehicle_demand      := 500
            // How many to build?
            set num_wanted             := 0
          endif
        endif
     74:
        if (bool_Race_Uses_Stellar_Manipulation_Ships) and (not bool_Are_We_Neutral_Player) then
          if Is_Component_Available("Beta Displacement Pulser") then
            set ai_design_type         := "Ship (Storm Destroyer)"
            set ai_vehicle_size        := AI_VEHICLE_SIZE_CRUISER
            set ai_vehicle_demand      := 500
            // How many to build?
            set num_wanted             := Sys_Trunc(num_facilities / num_per_facility_base * ship_wanted_mod)
          endif
        endif
     75:
        if (bool_Race_Uses_Evil_Stellar_Manipulation_Ships) and (not bool_Are_We_Neutral_Player) and (bool_Race_Is_Not_Alone) then
          if Is_Component_Available("Inverted Quantum Beam") then
            set ai_design_type         := "Ship (Black Hole Creator)"
            set ai_vehicle_size        := AI_VEHICLE_SIZE_CRUISER
            set ai_vehicle_demand      := 500
            // How many to build?
            set num_wanted             := Sys_Trunc(num_facilities / num_per_facility_base * ship_wanted_mod)
          endif
        endif
     76:
        if (bool_Race_Uses_Stellar_Manipulation_Ships) and (not bool_Are_We_Neutral_Player) then
          if Is_Component_Available("Quantum Graviton Beam") then
            set ai_design_type         := "Ship (Black Hole Destroyer)"
            set ai_vehicle_size        := AI_VEHICLE_SIZE_CRUISER
            set ai_vehicle_demand      := 500
            // How many to build?
            set num_wanted             := Sys_Trunc(num_facilities / num_per_facility_base * ship_wanted_mod)
          endif
        endif
     77:
        if (bool_Race_Uses_Evil_Stellar_Manipulation_Ships) and (not bool_Are_We_Neutral_Player) and (bool_Race_Is_Not_Alone) then
          if Is_Component_Available("Nucleonic Thresher Torpedo") then
            set ai_design_type         := "Ship (Nebulae Creator)"
            set ai_vehicle_size        := AI_VEHICLE_SIZE_CRUISER
            set ai_vehicle_demand      := 500
            // How many to build?
            set num_wanted             := Sys_Trunc(num_facilities / num_per_facility_base * ship_wanted_mod)
          endif
        endif
     78:
        if (bool_Race_Uses_Stellar_Manipulation_Ships) and (not bool_Are_We_Neutral_Player) then
          if Is_Component_Available("Nebulae Graviton Emitter") then
            set ai_design_type         := "Ship (Nebulae Destroyer)"
            set ai_vehicle_size        := AI_VEHICLE_SIZE_CRUISER
            set ai_vehicle_demand      := 500
            // How many to build?
            set num_wanted             := Sys_Trunc(num_facilities / num_per_facility_base * ship_wanted_mod)
          endif
        endif
    endcase

    // Add this design type to our list of vehicles to design/purchase
    if (ai_design_type <> "") then
      call lst_AI_Design_Type_Name.add(ai_design_type)
      call lst_AI_Design_Type_Vehicle_Size.add(ai_vehicle_size)
      call lst_AI_Design_Type_Task_Force_Role.add(ai_role)
      call lst_AI_Design_Type_Vehicle_Demand.add(ai_vehicle_demand)
      call lst_AI_Design_Type_Num_Wanted.add(num_wanted)
    endif
  endfor

  return TRUE
end

//------------------------------------------------------------------------
// Set_Race_Point_Modifiers
//------------------------------------------------------------------------
function Set_Race_Point_Modifiers returns boolean
params
vars
  research_pts:              long
  pct_research_pts:          long
  intel_pts:                 long
  pct_intel_pts:             long
begin

  // Get our point production
  set research_pts := Sys_Get_Empire_Current_Points(sys_long_Player_ID, POINT_TYPE_RESEARCH)
  set intel_pts := Sys_Get_Empire_Current_Points(sys_long_Player_ID, POINT_TYPE_INTELLIGENCE)

  if (research_pts > 0) or (intel_pts > 0) then
    set lng_Current_Pct_Research := Sys_Trunc(100 * research_pts / (research_pts + intel_pts))
    set lng_Current_Pct_Intel := Sys_Trunc(100 * intel_pts / (research_pts + intel_pts))
  endif

  // Determine our the percentage of our point production for research or intelligence
  if (bool_Race_At_Max_Tech) then
    // Debug Output
    call Sys_Debug_Print("Colonies", "    - At Max Tech!")
    if (bool_Intel_Is_Allowed) then
      // Switch all point production to intelligence
      set lng_Pct_Pts_Research := 0
      set lng_Pct_Pts_Intel := 100
    else
      // No need for any point production
      set lng_Pct_Pts_Research := 0
      set lng_Pct_Pts_Intel := 0
    endif
  else
    // Should we focus more on research or intel?
    if (bool_Intel_Is_Allowed) then
      if (not bool_Race_Is_Not_Alone) then
        set lng_Pct_Pts_Research := lng_Pct_Pts_Research + 10
      endif
      if (bool_Enemy_Far_Ahead_In_Research) then
        set lng_Pct_Pts_Research := lng_Pct_Pts_Research + 10
      endif
      if (bool_Enemy_Ahead_In_Research) then
        set lng_Pct_Pts_Research := lng_Pct_Pts_Research + 5
      endif
      if (bool_Enemy_Far_Ahead_In_Intel) then
        set lng_Pct_Pts_Research := lng_Pct_Pts_Research - 10
      endif
      if (bool_Enemy_Ahead_In_Intel) then
        set lng_Pct_Pts_Research := lng_Pct_Pts_Research - 20
      endif
      if (bool_Enemy_Intel_Overload) then
        set lng_Pct_Pts_Research := lng_Pct_Pts_Research - 30
      endif
      // Set intel
      set lng_Pct_pts_Intel := Sys_Max_Long(0, 100 - lng_Pct_pts_Research)
    else
      set lng_Pct_Pts_Research := 100
    endif
  endif

  // Don't allow our production percentages to be less than 0 or more than 100
  set lng_Pct_pts_Research := Sys_Min_Long(lng_Pct_Pts_Research, 100)
  set lng_Pct_pts_Research := Sys_Max_Long(lng_Pct_Pts_Research, 0)
  set lng_Pct_pts_Intel := Sys_Min_Long(lng_Pct_Pts_Intel, 100)
  set lng_Pct_pts_Intel := Sys_Max_Long(lng_Pct_Pts_Intel, 0)

  // Debug output
  call Sys_Debug_Print("Resources", "-----------------")
  call Sys_Debug_Print("Resources", "Point Production:")
  call Sys_Debug_Print("Resources", "  - Research Points = " + Sys_Convert_Long_To_String(research_pts))
  call Sys_Debug_Print("Resources", "    - Actual Research Pct = " + Sys_Convert_Long_To_String(lng_Current_Pct_Research) + "%")
  call Sys_Debug_Print("Resources", "    - Target Research Pct = " + Sys_Convert_Long_To_String(lng_Pct_Pts_Research) + "%")
  call Sys_Debug_Print("Resources", "  - Intelligence Points = " + Sys_Convert_Long_To_String(intel_pts))
  call Sys_Debug_Print("Resources", "    - Actual Intel Pct = " + Sys_Convert_Long_To_String(lng_Current_Pct_Intel) + "%")
  call Sys_Debug_Print("Resources", "    - Target Intel Pct = " + Sys_Convert_Long_To_String(lng_Pct_Pts_Intel) + "%")

  return TRUE
end

//------------------------------------------------------------------------
// Set_Race_Resource_Modifiers
//------------------------------------------------------------------------
function Set_Race_Resource_Modifiers returns boolean
params
vars
  resources_income:          resources
  resources_trade:           resources
  resources_spent:           resources
  resources_stored:          resources
  resources_maintenance:     resources
  income_minerals:           real
  income_organics:           real
  income_radioactives:       real
  production_minerals:       real
  production_organics:       real
  production_radioactives:   real
  trade_minerals:            real
  trade_organics:            real
  trade_radioactives:        real
  stored_minerals:           real
  stored_organics:           real
  stored_radioactives:       real
  expenses_minerals:         real
  expenses_organics:         real
  expenses_radioactives:     real
  maintenance_minerals:      real
  maintenance_organics:      real
  maintenance_radioactives:  real
  max_maint_minerals:        real
  max_maint_organics:        real
  max_maint_radioactives:    real
  new_minerals:              long
  low_minerals:              real
  high_minerals:             real
  new_organics:              long
  low_organics:              real
  high_organics:             real
  new_radioactives:          long
  low_radioactives:          real
  high_radioactives:         real
  num_trade_treaties:        long
  pct_minerals_trade:        real
  pct_organics_trade:        real
  pct_radioactives_trade:    real
  num_minerals:              long
  num_organics:              long
  num_radioactives:          long
  num_monolith:              long
  buf_low_prod:              real
  buf_high_prod:             real
  debug_str:                 string
begin

  // Get our resource income and expenses
  call resources_income.assign(Compute_Resource_Income())
  call resources_trade.assign(Sys_AI_Empire_Stats_Get_Total_Resources_From_Trade(sys_long_Player_ID))
  call resources_spent.assign(Compute_Resources_Spent())
  call resources_stored.assign(Compute_Resources_Stored())
  call resources_maintenance.assign(Sys_AI_Empire_Stats_Get_Total_Maintenance_Resources_Expenses(sys_long_Player_ID))

  // Get our resources received
  set income_minerals := resources_income.get(RESOURCE_TYPE_MINERALS)
  set income_organics := resources_income.get(RESOURCE_TYPE_ORGANICS)
  set income_radioactives := resources_income.get(RESOURCE_TYPE_RADIOACTIVES)

  // Get our resources from trade
  set trade_minerals := resources_trade.get(RESOURCE_TYPE_MINERALS)
  set trade_organics := resources_trade.get(RESOURCE_TYPE_ORGANICS)
  set trade_radioactives := resources_trade.get(RESOURCE_TYPE_RADIOACTIVES)

  // Get our resources from production
  set production_minerals := income_minerals - trade_minerals
  set production_organics := income_organics - trade_organics
  set production_radioactives := income_radioactives - trade_radioactives

  // Get our current stored resources
  set stored_minerals := resources_stored.get(RESOURCE_TYPE_MINERALS)
  set stored_organics := resources_stored.get(RESOURCE_TYPE_ORGANICS)
  set stored_radioactives := resources_stored.get(RESOURCE_TYPE_RADIOACTIVES)

  // Note our maximum storage levels
  set real_Max_Minerals_Storage := Sys_AI_Empire_Stats_Get_Colonies_Statistics_Real(sys_long_Player_ID, COLONIES_STATS_FILTER_MAX_RESOURCE_STORAGE_MINERALS)
  set real_Max_Organics_Storage := Sys_AI_Empire_Stats_Get_Colonies_Statistics_Real(sys_long_Player_ID, COLONIES_STATS_FILTER_MAX_RESOURCE_STORAGE_ORGANICS)
  set real_Max_Radioactives_Storage := Sys_AI_Empire_Stats_Get_Colonies_Statistics_Real(sys_long_Player_ID, COLONIES_STATS_FILTER_MAX_RESOURCE_STORAGE_RADIOACTIVES)

  // Get our resource expenses
  set expenses_minerals := resources_spent.get(RESOURCE_TYPE_MINERALS)
  set expenses_organics := resources_spent.get(RESOURCE_TYPE_ORGANICS)
  set expenses_radioactives := resources_spent.get(RESOURCE_TYPE_RADIOACTIVES)

  // Get our maintenance expenses
  set maintenance_minerals := resources_maintenance.get(RESOURCE_TYPE_MINERALS)
  set maintenance_organics := resources_maintenance.get(RESOURCE_TYPE_ORGANICS)
  set maintenance_radioactives := resources_maintenance.get(RESOURCE_TYPE_RADIOACTIVES)

  // Debug output
  call Sys_Debug_Print("Resources", "----------------")
  call Sys_Debug_Print("Resources", "Resource Income:")
  set debug_str := "  - Total Received = " + Sys_Convert_Real_To_String(income_minerals) + " Minerals, " + Sys_Convert_Real_To_String(income_organics) + " Organics, " + Sys_Convert_Real_To_String(income_radioactives) + " Radioactives"
  call Sys_Debug_Print("Resources", debug_str)
  set debug_str := "    - From Production = " + Sys_Convert_Real_To_String(production_minerals) + " Minerals, " + Sys_Convert_Real_To_String(production_organics) + " Organics, " + Sys_Convert_Real_To_String(production_radioactives) + " Radioactives"
  call Sys_Debug_Print("Resources", debug_str)
  set debug_str := "    - From Trade = " + Sys_Convert_Real_To_String(trade_minerals) + " Minerals, " + Sys_Convert_Real_To_String(trade_organics) + " Organics, " + Sys_Convert_Real_To_String(trade_radioactives) + " Radioactives"
  call Sys_Debug_Print("Resources", debug_str)
  set debug_str := "  - Max Storage Amount = " + Sys_Convert_Real_To_String(real_Max_Minerals_Storage) + " Minerals, " + Sys_Convert_Real_To_String(real_Max_Organics_Storage) + " Organics, " + Sys_Convert_Real_To_String(real_Max_Radioactives_Storage) + " Radioactives"
  call Sys_Debug_Print("Resources", debug_str)
  set debug_str := "    - Current Storage Amount = " + Sys_Convert_Real_To_String(stored_minerals) + " Minerals, " + Sys_Convert_Real_To_String(stored_organics) + " Organics, " + Sys_Convert_Real_To_String(stored_radioactives) + " Radioactives"
  call Sys_Debug_Print("Resources", debug_str)

  call Sys_Debug_Print("Resources", "------------------")
  call Sys_Debug_Print("Resources", "Resource Expenses:")
  set debug_str := "  - Total Expenses = " + Sys_Convert_Real_To_String(expenses_minerals) + " Minerals, " + Sys_Convert_Real_To_String(expenses_organics) + " Organics, " + Sys_Convert_Real_To_String(expenses_radioactives)  + " Radioactives"
  call Sys_Debug_Print("Resources", debug_str)
  set debug_str := "    - From Maintenance = " + Sys_Convert_Real_To_String(maintenance_minerals) + " Minerals, " + Sys_Convert_Real_To_String(maintenance_organics) + " Organics, " + Sys_Convert_Real_To_String(maintenance_radioactives) + " Radioactives"
  call Sys_Debug_Print("Resources", debug_str)

  // Resource infusion if an AI player (accidentally) goes bankrupt
  if (bool_Are_We_Computer_Player) then
    // Mineral Boost
    if (stored_minerals <= 0) then
      set bool_Race_Minerals_Emergency := TRUE
      set new_minerals := Sys_Max_Long(0, Sys_Trunc(expenses_minerals - production_minerals))
      call Sys_Debug_Print("Resources", "    - Added " + Sys_Convert_Long_To_String(new_minerals) + " emergency Minerals")
    endif
    // Organics Boost
    if (stored_organics <= 0) then
      set bool_Race_Organics_Emergency := TRUE
      set new_organics := Sys_Max_Long(0, Sys_Trunc(expenses_organics - production_organics))
      call Sys_Debug_Print("Resources", "    - Added " + Sys_Convert_Long_To_String(new_organics) + " emergency Organics")
    endif
    // Radioactives Boost
    if (stored_minerals <= 0) then
      set bool_Race_Radioactives_Emergency := TRUE
      set new_radioactives := Sys_Max_Long(0, Sys_Trunc(expenses_radioactives - production_radioactives))
      call Sys_Debug_Print("Resources", "    - Added " + Sys_Convert_Long_To_String(new_radioactives) + " emergency Radioactives")
    endif
    // Change the storage amount
    if (new_minerals > 0) or (new_organics > 0) or (new_radioactives > 0) then
      call Sys_Change_Empire_Points(sys_long_Player_ID, new_minerals, new_organics, new_radioactives)
    endif
  endif

  // Identify our low and high amounts for stored resources
  set low_minerals := Sys_Max_Real(5000.0, maintenance_minerals * 0.5)
  set high_minerals := Sys_Max_Real(50000.0, maintenance_minerals * 2.0)
  set low_organics := Sys_Max_Real(3000.0, maintenance_organics * 0.5)
  set high_organics := Sys_Max_Real(20000.0, maintenance_organics * 2.0)
  set low_radioactives := Sys_Max_Real(3000.0, maintenance_radioactives * 0.5)
  set high_radioactives := Sys_Max_Real(20000.0, maintenance_radioactives * 2.0)

  // Debug output
  call Sys_Debug_Print("Resources", "----------------")
  call Sys_Debug_Print("Resources", "Resource Status:")

  // Determine our resource balances and general resource levels
  call Compute_Resource_Balances()
  call Compute_Resource_Levels()

  // Debug output - Minerals
  call Sys_Debug_Print("Resources", "  - Minerals")

  if (lng_Minerals_Surplus > 0) then
    call Sys_Debug_Print("Resources", "    - Minerals surplus = " + Sys_Convert_Long_To_String(lng_Minerals_Surplus))
  else
    call Sys_Debug_Print("Resources", "    - Minerals deficit = " + Sys_Convert_Long_To_String(lng_Minerals_Deficit))
  endif
  if (bool_Race_Minerals_Low) then
    call Sys_Debug_Print("Resources", "    - Minerals storage low")
  endif
  if (bool_Race_Minerals_High) then
    call Sys_Debug_Print("Resources", "    - Minerals storage high")
  endif
  if (bool_Race_Minerals_Adequate) then
    call Sys_Debug_Print("Resources", "    - Minerals storage adequate")
  endif
  if (bool_Race_Needs_Minerals_Storage) then
    call Sys_Debug_Print("Resources", "    - Need more Minerals storage capacity!")
  endif

  // Debug output - Organics
  call Sys_Debug_Print("Resources", "  - Organics")

  if (lng_Organics_Surplus > 0) then
    call Sys_Debug_Print("Resources", "    - Organics surplus = " + Sys_Convert_Long_To_String(lng_Organics_Surplus))
  else
    call Sys_Debug_Print("Resources", "    - Organics deficit = " + Sys_Convert_Long_To_String(lng_Organics_Deficit))
  endif
  if (bool_Race_Organics_Low) then
    call Sys_Debug_Print("Resources", "    - Organics storage low")
  endif
  if (bool_Race_Organics_High) then
    call Sys_Debug_Print("Resources", "    - Organics storage high")
  endif
  if (bool_Race_Organics_Adequate) then
    call Sys_Debug_Print("Resources", "    - Organics storage adequate")
  endif
  if (bool_Race_Needs_Organics_Storage) then
    call Sys_Debug_Print("Resources", "    - Need more Organics storage capacity!")
  endif

  // Debug output - Radioactives
  call Sys_Debug_Print("Resources", "  - Radioactives")

  if (lng_Radioactives_Surplus > 0) then
    call Sys_Debug_Print("Resources", "    - Radioactives surplus = " + Sys_Convert_Long_To_String(lng_Radioactives_Surplus))
  else
    call Sys_Debug_Print("Resources", "    - Radioactives deficit = " + Sys_Convert_Long_To_String(lng_Radioactives_Deficit))
  endif
  if (bool_Race_Radioactives_Low) then
    call Sys_Debug_Print("Resources", "    - Radioactives storage low")
  endif
  if (bool_Race_Radioactives_High) then
    call Sys_Debug_Print("Resources", "    - Radioactives storage high")
  endif
  if (bool_Race_Radioactives_Adequate) then
    call Sys_Debug_Print("Resources", "    - Radioactives storage adequate")
  endif
  if (bool_Race_Needs_Radioactives_Storage) then
    call Sys_Debug_Print("Resources", "    - Need more Radioactives storage capacity!")
  endif

  // Calculate our resource production and spending proportional percentages
  set lng_Minerals_Prod_Pct := Sys_Round(production_minerals / (production_minerals + production_organics + production_radioactives) * 100)
  set lng_Organics_Prod_Pct := Sys_Round(production_organics / (production_minerals + production_organics + production_radioactives) * 100)
  set lng_Radioactives_Prod_Pct := Sys_Round(production_radioactives / (production_minerals + production_organics + production_radioactives) * 100)

  set lng_Minerals_Spend_Pct := Sys_Round(expenses_minerals / (expenses_minerals + expenses_organics + expenses_radioactives) * 100)
  set lng_Organics_Spend_Pct := Sys_Round(expenses_organics / (expenses_minerals + expenses_organics + expenses_radioactives) * 100)
  set lng_Radioactives_Spend_Pct := Sys_Round(expenses_radioactives / (expenses_minerals + expenses_organics + expenses_radioactives) * 100)

  // Debug output
  call Sys_Debug_Print("Resources", "  - Production Percentages:")
  set debug_str := "    - " + Sys_Convert_Long_To_String(lng_Minerals_Prod_Pct) + "% Minerals, " + Sys_Convert_Long_To_String(lng_Organics_Prod_Pct) + "% Organics, " + Sys_Convert_Long_To_String(lng_Radioactives_Prod_Pct) + "% Radioactives"
  call Sys_Debug_Print("Resources", debug_str)
  call Sys_Debug_Print("Resources", "  - Spending Percentages:")
  set debug_str := "    - " + Sys_Convert_Long_To_String(lng_Minerals_Spend_Pct) + "% Minerals, " + Sys_Convert_Long_To_String(lng_Organics_Spend_Pct) + "% Organics, " + Sys_Convert_Long_To_String(lng_Radioactives_Spend_Pct) + "% Radioactives"
  call Sys_Debug_Print("Resources", debug_str)

  // Determine our tolerance for spending ratio compared to production ratio
  if (lng_AI_Empire_Num_Monolith_Facilities > (lng_AI_Empire_Num_Minerals_Facilities + lng_AI_Empire_Num_Organics_Facilities + lng_AI_Empire_Num_Radioactives_Facilities)) then
    set buf_low_prod := 0.7
    set buf_high_prod := 1.3
  else
    set buf_low_prod := 0.8
    set buf_high_prod := 1.2
  endif

  // Are we producing resources in proportion with our spending?
  // Minerals
  if (lng_Minerals_Prod_Pct < lng_Minerals_Spend_Pct * buf_low_prod) then
    set bool_Race_Minerals_Prod_Low := TRUE
    // Debug output
    call Sys_Debug_Print("Resources", "    - Minerals production ratio low")
  endif
  if (lng_Minerals_Prod_Pct > lng_Minerals_Spend_Pct * buf_high_prod) then
    set bool_Race_Minerals_Prod_High := TRUE
    // Debug output
    call Sys_Debug_Print("Resources", "    - Minerals production ratio high")
  endif
  // Organics
  if (lng_Organics_Prod_Pct < lng_Organics_Spend_Pct * buf_low_prod) then
    set bool_Race_Organics_Prod_Low := TRUE
    // Debug output
    call Sys_Debug_Print("Resources", "    - Organics production ratio low")
  endif
  if (lng_Organics_Prod_Pct > lng_Organics_Spend_Pct * buf_high_prod) then
    set bool_Race_Organics_Prod_High := TRUE
    // Debug output
    call Sys_Debug_Print("Resources", "    - Organics production ratio high")
  endif
  // Radioactives
  if (lng_Radioactives_Prod_Pct < lng_Radioactives_Spend_Pct * buf_low_prod) then
    set bool_Race_Radioactives_Prod_Low := TRUE
    // Debug output
    call Sys_Debug_Print("Resources", "    - Radioactives production ratio low")
  endif
  if (lng_Radioactives_Prod_Pct > lng_Radioactives_Spend_Pct * buf_high_prod) then
    set bool_Race_Radioactives_Prod_High := TRUE
    // Debug output
    call Sys_Debug_Print("Resources", "    - Radioactives production ratio high")
  endif

  // Determine how much trade income to contribute to maintenance
  set num_trade_treaties := Get_Number_Of_Trade_Treaties()

  // Base trade income contribution to maintenance on the number of trade treaties we have
  if (maintenance_minerals > 0) and (maintenance_organics > 0) and (maintenance_radioactives > 0) then
    set pct_minerals_trade := 0.1 * (stored_minerals / maintenance_minerals) + (0.1 * (num_trade_treaties ^ 0.5))
    set pct_organics_trade := 0.1 * (stored_organics / maintenance_organics) + (0.1 * (num_trade_treaties ^ 0.5))
    set pct_radioactives_trade := 0.1 * (stored_radioactives / maintenance_radioactives) + (0.1 * (num_trade_treaties ^ 0.5))
  endif

  // Cap trade income contribution to 75% when storage is high, 50% if it's not high
  if (bool_Race_Minerals_High) and (bool_Race_Organics_High) and (bool_Race_Radioactives_High) then
    set pct_minerals_trade := Sys_Min_Real(pct_minerals_trade, 0.75)
    set pct_organics_trade := Sys_Min_Real(pct_organics_trade, 0.75)
    set pct_radioactives_trade := Sys_Min_Real(pct_radioactives_trade, 0.75)
  else
    set pct_minerals_trade := Sys_Min_Real(pct_minerals_trade, 0.50)
    set pct_organics_trade := Sys_Min_Real(pct_organics_trade, 0.50)
    set pct_radioactives_trade := Sys_Min_Real(pct_radioactives_trade, 0.50)
  endif


  // Increase trade income contribution to maintenance if we are using AI team mode
  if (bool_AI_Team_Mode_On) and (bool_Are_We_Computer_Player) then
    set pct_minerals_trade := 0.75
    set pct_organics_trade := 0.75
    set pct_radioactives_trade := 0.75
  endif

  // Reduce trade income contribution to maintenance if we can't protect our treaties from intel attacks
  if (bool_Enemy_Intel_Overload) then
    set pct_minerals_trade := Sys_Min_Real(pct_minerals_trade, 0.25)
    set pct_organics_trade := Sys_Min_Real(pct_organics_trade, 0.25)
    set pct_radioactives_trade := Sys_Min_Real(pct_radioactives_trade, 0.25)
  endif

  // Debug output
  call Sys_Debug_Print("Resources", "  - Trade income contribution to maintenance:")
  set debug_str := "    - " + Sys_Convert_Real_To_String((pct_minerals_trade * 100.0)) + "% Minerals, " + Sys_Convert_Real_To_String((pct_minerals_trade * 100.0)) + "% Organics, " + Sys_Convert_Real_To_String((pct_radioactives_trade * 100.0)) + "% Radioactives"
  call Sys_Debug_Print("Resources", debug_str)

  // Compute our maximum maintenance levels
  if (not bool_Race_Minerals_Low) then
    set max_maint_minerals := production_minerals + (trade_minerals * pct_minerals_trade)
  else
    if (trade_minerals > 0) then
      set max_maint_minerals := production_minerals
    else
      set max_maint_minerals := production_minerals * 0.9
    endif
  endif

  if (not bool_Race_Organics_Low) then
    set max_maint_organics := production_organics + (trade_organics * pct_organics_trade)
  else
    if (trade_organics > 0) then
      set max_maint_organics := production_organics
    else
      set max_maint_organics := production_organics * 0.9
    endif
  endif

  if (not bool_Race_Radioactives_Low) then
    set max_maint_radioactives := production_radioactives + (trade_radioactives * pct_radioactives_trade)
  else
    if (trade_radioactives > 0) then
      set max_maint_radioactives := production_radioactives
    else
      set max_maint_radioactives := production_radioactives * 0.9
    endif
  endif

  // Debug output
  set debug_str := "  - Maintenance Budget = " + Sys_Convert_Real_To_String(max_maint_minerals) + " Minerals, " + Sys_Convert_Real_To_String(max_maint_organics) + " Organics, " + Sys_Convert_Real_To_String(max_maint_radioactives) + " Radioactives"
  call Sys_Debug_Print("Resources", debug_str)

  // Determine if our maintenance costs are too high
  if (maintenance_minerals > max_maint_minerals) or (maintenance_organics > max_maint_organics) or (maintenance_radioactives > max_maint_radioactives) then
    set bool_Race_Maintenance_High := TRUE
    // Debug output
    call Sys_Debug_Print("Resources", "    - Maintenance costs above budget")
  else
    set bool_Race_Maintenance_Low := TRUE
    // Debug output
    call Sys_Debug_Print("Resources", "    - Maintenance costs below budget")
  endif

  // Decrease our vehicle demand or scrap times based on our low resource indicators
  if (bool_Race_Minerals_Low) then
    set lng_Ship_Demand_Reduction_Factor := lng_Ship_Demand_Reduction_Factor + 1
    set lng_Unit_Demand_Reduction_Factor := lng_Unit_Demand_Reduction_Factor + 1
    set lng_AI_Design_Time_Until_Retrofit := lng_AI_Design_Time_Until_Retrofit + 10
    set lng_Ship_Obsolete_Time_To_Scrap := lng_Ship_Obsolete_Time_To_Scrap - 10
    set lng_Unit_Obsolete_Time_To_Scrap := lng_Unit_Obsolete_Time_To_Scrap - 20
    set lng_Emergency_Scrap_Pts := lng_Emergency_Scrap_Pts + 1
    // Further measures if our minerals have been continuously low
    if (bool_Race_Minerals_Cont_Low) then
      set lng_Ship_Demand_Reduction_Factor := lng_Ship_Demand_Reduction_Factor + 2
      set lng_Unit_Demand_Reduction_Factor := lng_Unit_Demand_Reduction_Factor + 2
      set lng_AI_Design_Time_Until_Retrofit := lng_AI_Design_Time_Until_Retrofit + 10
      set lng_Ship_Obsolete_Time_To_Scrap := lng_Ship_Obsolete_Time_To_Scrap - 10
      set lng_Unit_Obsolete_Time_To_Scrap := lng_Unit_Obsolete_Time_To_Scrap - 20
      set lng_Emergency_Scrap_Pts := lng_Emergency_Scrap_Pts + 1
    endif
  endif

  if (bool_Race_Organics_Low) then
    set lng_Ship_Demand_Reduction_Factor := lng_Ship_Demand_Reduction_Factor + 1
    set lng_Unit_Demand_Reduction_Factor := lng_Unit_Demand_Reduction_Factor + 1
    set lng_AI_Design_Time_Until_Retrofit := lng_AI_Design_Time_Until_Retrofit + 5
    set lng_Ship_Obsolete_Time_To_Scrap := lng_Ship_Obsolete_Time_To_Scrap - 5
    set lng_Unit_Obsolete_Time_To_Scrap := lng_Unit_Obsolete_Time_To_Scrap - 10
    set lng_Emergency_Scrap_Pts := lng_Emergency_Scrap_Pts + 1
    // Further measures if our organics have been continuously low
    if (bool_Race_Organics_Cont_Low) then
      set lng_Ship_Demand_Reduction_Factor := lng_Ship_Demand_Reduction_Factor + 1
      set lng_Unit_Demand_Reduction_Factor := lng_Unit_Demand_Reduction_Factor + 1
      set lng_AI_Design_Time_Until_Retrofit := lng_AI_Design_Time_Until_Retrofit + 5
      set lng_Ship_Obsolete_Time_To_Scrap := lng_Ship_Obsolete_Time_To_Scrap - 5
      set lng_Unit_Obsolete_Time_To_Scrap := lng_Unit_Obsolete_Time_To_Scrap - 10
      set lng_Emergency_Scrap_Pts := lng_Emergency_Scrap_Pts + 1
    endif
  endif

  if (bool_Race_Radioactives_Low) then
    set lng_Ship_Demand_Reduction_Factor := lng_Ship_Demand_Reduction_Factor + 1
    set lng_Unit_Demand_Reduction_Factor := lng_Unit_Demand_Reduction_Factor + 1
    set lng_AI_Design_Time_Until_Retrofit := lng_AI_Design_Time_Until_Retrofit + 5
    set lng_Ship_Obsolete_Time_To_Scrap := lng_Ship_Obsolete_Time_To_Scrap - 5
    set lng_Unit_Obsolete_Time_To_Scrap := lng_Unit_Obsolete_Time_To_Scrap - 10
    set lng_Emergency_Scrap_Pts := lng_Emergency_Scrap_Pts + 1
    // Further measures if our radioactives have been continuously low
    if (bool_Race_Radioactives_Cont_Low) then
      set lng_Ship_Demand_Reduction_Factor := lng_Ship_Demand_Reduction_Factor + 1
      set lng_Unit_Demand_Reduction_Factor := lng_Unit_Demand_Reduction_Factor + 1
      set lng_AI_Design_Time_Until_Retrofit := lng_AI_Design_Time_Until_Retrofit + 5
      set lng_Ship_Obsolete_Time_To_Scrap := lng_Ship_Obsolete_Time_To_Scrap - 5
      set lng_Unit_Obsolete_Time_To_Scrap := lng_Unit_Obsolete_Time_To_Scrap - 10
      set lng_Emergency_Scrap_Pts := lng_Emergency_Scrap_Pts + 1
    endif
  endif

  // Adjustments to target vehicle wanted numbers based on maintenance costs
  if (bool_Race_Maintenance_High) then
    // Reduce ship and unit wanted numbers by 10%
    set lng_Ship_Demand_Reduction_Factor := lng_Ship_Demand_Reduction_Factor + 1
    set lng_Unit_Demand_Reduction_Factor := lng_Unit_Demand_Reduction_Factor + 1
    set lng_Ship_Obsolete_Time_To_Scrap := lng_Ship_Obsolete_Time_To_Scrap - 10
    set lng_Unit_Obsolete_Time_To_Scrap := lng_Unit_Obsolete_Time_To_Scrap - 20
    set lng_Emergency_Scrap_Pts := lng_Emergency_Scrap_Pts + 1
    // Further measures if our maintenance has been continuously high (more than 10 turns)
    if (bool_Race_Maintenance_Cont_High) then
      // Reduce ship and unit wanted numbers by another 10%
      set lng_Ship_Demand_Reduction_Factor := lng_Ship_Demand_Reduction_Factor + 1
      set lng_Unit_Demand_Reduction_Factor := lng_Unit_Demand_Reduction_Factor + 1
      set lng_AI_Design_Time_Until_Retrofit := lng_AI_Design_Time_Until_Retrofit + 5
      set lng_Ship_Obsolete_Time_To_Scrap := lng_Ship_Obsolete_Time_To_Scrap - 5
      set lng_Unit_Obsolete_Time_To_Scrap := lng_Unit_Obsolete_Time_To_Scrap - 10
      set lng_Emergency_Scrap_Pts := lng_Emergency_Scrap_Pts + 1
    endif
  endif

  if (bool_Race_Maintenance_Low) then
    // Increase ship and unit wanted numbers by 100% and 50% if maintenance is low
    set lng_Ship_Demand_Reduction_Factor := lng_Ship_Demand_Reduction_Factor - 10
    set lng_Unit_Demand_Reduction_Factor := lng_Unit_Demand_Reduction_Factor - 5
  endif

  // Increase urgency to scrap obsolete units if we are in a resource emergency
  if (bool_Race_Minerals_Emergency) or (bool_Race_Organics_Emergency) or (bool_Race_Radioactives_Emergency) then
    set lng_Emergency_Scrap_Pts := lng_Emergency_Scrap_Pts + 1
  endif

  // If we are at maximum number of ships or units, increase our scrap rate to keep our items updated
  if (bool_Race_At_Max_Ships) then
    set lng_Ship_Obsolete_Time_To_Scrap := lng_Ship_Obsolete_Time_To_Scrap - 30
    set lng_AI_Design_Time_Until_Retrofit := lng_AI_Design_Time_Until_Retrofit - 5
  endif
  if (bool_Race_At_Max_Units) then
    set lng_Unit_Obsolete_Time_To_Scrap := lng_Unit_Obsolete_Time_To_Scrap - 30
  endif

  // Set the maximum amount of ships to retrofit each turn
  if (bool_Race_Minerals_High) and (bool_Race_Organics_High) and (bool_Race_Radioactives_High) then
    set lng_Max_Ships_To_Retrofit := Sys_Trunc(lng_AI_Available_Fleet_Ships_Count ^ 0.6)
  else
    if (bool_Race_Minerals_Low) or (bool_Race_Organics_low) or (bool_Race_Radioactives_Low) then
      if (lng_Emergency_Scrap_Pts > 2) then
        set lng_Max_Ships_To_Retrofit := 0
      else
        set lng_Max_Ships_To_Retrofit := Sys_Trunc(lng_AI_Available_Fleet_Ships_Count ^ 0.2)
      endif
    else
      set lng_Max_Ships_To_Retrofit := Sys_Trunc(lng_AI_Available_Fleet_Ships_Count ^ 0.5)
    endif
  endif

  return TRUE
end

//------------------------------------------------------------------------
// AI_Set_Political_Anger_For_Log_Types
//------------------------------------------------------------------------
function AI_Set_Political_Anger_For_Log_Types returns boolean
params
vars
begin

  // Sets the anger severity level for events displayed in our log

  // Combat events
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_SPACE_COMBAT_DEFENSE_LOST)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Space_Combat_Lost + 2)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_SPACE_COMBAT_DEFENSE_WON)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Space_Combat_Won - 1)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_SPACE_COMBAT_OFFENSE_LOST + 1)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Space_Combat_Lost - 1)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_SPACE_COMBAT_OFFENSE_WON)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Space_Combat_Won - 2)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_SPACE_COMBAT_STALEMATE)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Space_Combat_Stalemate)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_GROUND_COMBAT_DEFENSE_LOST)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Ground_Combat_Lost)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_GROUND_COMBAT_DEFENSE_WON)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Ground_Combat_Won)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_GROUND_COMBAT_OFFENSE_LOST)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Ground_Combat_Lost)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_GROUND_COMBAT_OFFENSE_WON)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Ground_Combat_Lost)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_GROUND_COMBAT_STALEMATE)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Ground_Combat_Stalemate)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_MINE_EXPLOSION)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Mine_Explosion)

  // Diplomatic events
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_FROM_TREATY_SYSTEM_MAPS_PROVIDED)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Treaty_Maps_Received)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_FROM_TREATY_TECHNOLOGY_PROVIDED)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Treaty_Tech_Provided)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_FROM_TREATY_DESIGNS_PROVIDED)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Treaty_Designs_Received)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_FROM_TREATY_COMM_CHANNELS_PROVIDED)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Treaty_Comm_Channels_Provided)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_FROM_TREATY_ESPIONAGE_INFO_PROVIDED)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Treaty_Espionage_Info_Provided)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_FROM_TREATY_COMBAT_REPORTS_PROVIDED)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Treaty_Combat_Info_Provided)

  // Intelligence events
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_ESPIONAGE_AGAINST_US)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Espionage)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_SABOTAGE_AGAINST_US)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Sabotage)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_PLANET_CARGO_DAMAGE)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Planet_Cargo_Bomb)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_PLANET_CONDITION_CHANGE)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Planet_Conditions_Change)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_PLANET_PLAGUED)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Planet_Plagued)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_PLANET_POP_CHANGE)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Planet_Population_Change)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_PLANET_POP_ANGER_CHANGE)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Planet_Anger_Change)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_PLANET_POP_RIOTING)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Planet_Riot)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_PLANET_POP_REBEL)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Planet_Rebel)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_PLANET_VALUE_CHANGE)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Planet_Value_Change)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_POINTS_CHANGE)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Points_Change)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_SHIP_CARGO_DAMAGE)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Ship_Cargo_Bomb)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_SHIP_DAMAGED)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Ship_Damaged)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_SHIP_EXPERIENCE_CHANGE)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Ship_Lost_Experience)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_SHIP_LOSE_MOVEMENT)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Ship_Lost_Movement)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_SHIP_LOSE_SUPPLY)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Ship_Lost_Supply)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_SHIP_ORDERS_CHANGE)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Ship_Orders_Changed)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_SHIP_REBEL)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Ship_Rebel)

  // Stellar Manipulation Events
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_STELLAR_PLANET_DESTROYED)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Planet_Destroyed)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_STELLAR_STAR_DESTROYED)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Star_Destroyed)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_STELLAR_BLACK_HOLE_CREATED)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Blackhole_Created)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_STELLAR_NEBULAE_CREATED)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Nebulae_Created)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_STELLAR_STORM_CREATED)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_Nebulae_Created)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_STELLAR_WP_CLOSED)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_WP_Closed)
  call lst_Politics_Anger_Event_Type.add(LOG_TYPE_STELLAR_WP_OPENED)
  call lst_Politics_Anger_Event_Amount.add(lng_AI_Anger_Amount_WP_Opened)

  return TRUE
end

//------------------------------------------------------------------------
// AI_Set_Political_Anger_For_Messages
//------------------------------------------------------------------------
function AI_Set_Political_Anger_For_Messages returns boolean
params
vars
begin

  // Set our anger amounts for diplomatic messages
  call lst_Politics_Anger_Message_Type.add(POLITICS_MSG_GENERAL_MESSAGE)
  call lst_Politics_Anger_Message_Amount.add(lng_AI_Anger_Amount_Msg_General)
  call lst_Politics_Anger_Message_Type.add(POLITICS_MSG_REPLY_TO_MESSAGE)
  call lst_Politics_Anger_Message_Amount.add(lng_AI_Anger_Amount_Msg_Reply)
  call lst_Politics_Anger_Message_Type.add(POLITICS_MSG_DECLARE_WAR)
  call lst_Politics_Anger_Message_Amount.add(lng_AI_Anger_Amount_Msg_Declare_War)
  call lst_Politics_Anger_Message_Type.add(POLITICS_MSG_GRANT_INDEPENDENCE)
  call lst_Politics_Anger_Message_Amount.add(lng_AI_Anger_Amount_Msg_Grant_Independence)
  call lst_Politics_Anger_Message_Type.add(POLITICS_MSG_PROPOSE_TREATY)
  call lst_Politics_Anger_Message_Amount.add(lng_AI_Anger_Amount_Msg_Propose_Treaty)
  call lst_Politics_Anger_Message_Type.add(POLITICS_MSG_ACCEPT_TREATY)
  call lst_Politics_Anger_Message_Amount.add(lng_AI_Anger_Amount_Msg_Accept_Treaty)
  call lst_Politics_Anger_Message_Type.add(POLITICS_MSG_ACCEPT_TREATY_CHANGES)
  call lst_Politics_Anger_Message_Amount.add(lng_AI_Anger_Amount_Msg_Accept_Treaty_Changes)
  call lst_Politics_Anger_Message_Type.add(POLITICS_MSG_REFUSE_TREATY)
  call lst_Politics_Anger_Message_Amount.add(lng_AI_Anger_Amount_Msg_Refuse_Treaty)
  call lst_Politics_Anger_Message_Type.add(POLITICS_MSG_REFUSE_TREATY_CHANGES)
  call lst_Politics_Anger_Message_Amount.add(lng_AI_Anger_Amount_Msg_Refuse_Treaty_Changes)
  call lst_Politics_Anger_Message_Type.add(POLITICS_MSG_COUNTER_TREATY_PROPOSAL)
  call lst_Politics_Anger_Message_Amount.add(lng_AI_Anger_Amount_Msg_Counter_Treaty)
  call lst_Politics_Anger_Message_Type.add(POLITICS_MSG_COUNTER_TREATY_CHANGES)
  call lst_Politics_Anger_Message_Amount.add(lng_AI_Anger_Amount_Msg_Counter_Treaty_Changes)
  call lst_Politics_Anger_Message_Type.add(POLITICS_MSG_BREAK_TREATY)
  call lst_Politics_Anger_Message_Amount.add(lng_AI_Anger_Amount_Msg_Break_Treaty)
  call lst_Politics_Anger_Message_Type.add(POLITICS_MSG_PROPOSE_TRADE)
  call lst_Politics_Anger_Message_Amount.add(lng_AI_Anger_Amount_Msg_Propose_Trade)
  call lst_Politics_Anger_Message_Type.add(POLITICS_MSG_ACCEPT_TRADE)
  call lst_Politics_Anger_Message_Amount.add(lng_AI_Anger_Amount_Msg_Accept_Trade)
  call lst_Politics_Anger_Message_Type.add(POLITICS_MSG_REFUSE_TRADE)
  call lst_Politics_Anger_Message_Amount.add(lng_AI_Anger_Amount_Msg_Refuse_Trade)
  call lst_Politics_Anger_Message_Type.add(POLITICS_MSG_COUNTER_TRADE)
  call lst_Politics_Anger_Message_Amount.add(lng_AI_Anger_Amount_Msg_Counter_Trade)
  call lst_Politics_Anger_Message_Type.add(POLITICS_MSG_REQUEST_GIFT)
  call lst_Politics_Anger_Message_Amount.add(lng_AI_Anger_Amount_Msg_Request_Gift)
  call lst_Politics_Anger_Message_Type.add(POLITICS_MSG_GIVE_GIFT)
  call lst_Politics_Anger_Message_Amount.add(lng_AI_Anger_Amount_Msg_Give_Gift)
  call lst_Politics_Anger_Message_Type.add(POLITICS_MSG_ACCEPT_GIFT)
  call lst_Politics_Anger_Message_Amount.add(lng_AI_Anger_Amount_Msg_Accept_Gift)
  call lst_Politics_Anger_Message_Type.add(POLITICS_MSG_REFUSE_GIFT)
  call lst_Politics_Anger_Message_Amount.add(lng_AI_Anger_Amount_Msg_Refuse_Gift)
  call lst_Politics_Anger_Message_Type.add(POLITICS_MSG_REQUEST_ACCEPT)
  call lst_Politics_Anger_Message_Amount.add(lng_AI_Anger_Amount_Msg_Request_Accept)
  call lst_Politics_Anger_Message_Type.add(POLITICS_MSG_REQUEST_REFUSE)
  call lst_Politics_Anger_Message_Amount.add(lng_AI_Anger_Amount_Msg_Request_Refuse)
  call lst_Politics_Anger_Message_Type.add(POLITICS_MSG_REQUEST_SURRENDER)
  call lst_Politics_Anger_Message_Amount.add(lng_AI_Anger_Amount_Msg_Request_Surrender)
  call lst_Politics_Anger_Message_Type.add(POLITICS_MSG_PROPOSE_NEW_ALLIANCE)
  call lst_Politics_Anger_Message_Amount.add(lng_AI_Anger_Amount_Msg_Propose_Alliance)
  call lst_Politics_Anger_Message_Type.add(POLITICS_MSG_ACCEPT_ALLIANCE)
  call lst_Politics_Anger_Message_Amount.add(lng_AI_Anger_Amount_Msg_Accept_Alliance)
  call lst_Politics_Anger_Message_Type.add(POLITICS_MSG_REFUSE_ALLIANCE)
  call lst_Politics_Anger_Message_Amount.add(lng_AI_Anger_Amount_Msg_Refuse_Alliance)
  call lst_Politics_Anger_Message_Type.add(POLITICS_MSG_BREAK_WITH_ALLIANCE)
  call lst_Politics_Anger_Message_Amount.add(lng_AI_Anger_Amount_Msg_Leave_Alliance)

  return TRUE
end

//------------------------------------------------------------------------
// AI_Set_Political_Anger_For_Wars
//------------------------------------------------------------------------
function AI_Set_Political_Anger_For_Wars returns boolean
params
vars
  war_modifier:              long
  treaty_modifier:           long
begin

  // Adjust our war/treaty modifiers for diplomatic status
  case lng_AI_Categorization
    AI_CATEGORY_PEACEFUL:
      set war_modifier := (5 * lng_AI_Num_Of_Wars) - (2 * lng_AI_Num_Of_Friendly_Treaties)
      set treaty_modifier := (-2 * lng_AI_Num_Of_Enemies)
    AI_CATEGORY_NEUTRAL:
      set war_modifier := (5 * lng_AI_Num_Of_Wars) - (2 * lng_AI_Num_Of_Friendly_Treaties)
      set treaty_modifier := (-2 * lng_AI_Num_Of_Enemies) + (lng_AI_Num_Of_Friendly_Treaties)
    AI_CATEGORY_AGGRESSIVE:
      set war_modifier := (5 * lng_AI_Num_Of_Wars) - (5 * lng_AI_Num_Of_Friendly_Treaties)
      set treaty_modifier := (-2 * lng_AI_Num_Of_Enemies) + (5 * lng_AI_Num_Of_Friendly_Treaties)
    AI_CATEGORY_XENOPHOBIC:
      set war_modifier := (5 * lng_AI_Num_Of_Wars) - (5 * lng_AI_Num_Of_Friendly_Treaties)
      set treaty_modifier := (-2 * lng_AI_Num_Of_Enemies) + (5 * lng_AI_Num_Of_Friendly_Treaties)
  endcase

  // Adjust our war/treaty modifiers for combat performance
  if (bool_Race_Space_Combat_Good) then
    set war_modifier := war_modifier - 5
  endif
  if (bool_Race_Space_Combat_Poor) then
    set war_modifier := war_modifier + 10
    set treaty_modifier := treaty_modifier - 5
  endif
  if (bool_Race_Ground_Combat_Good) then
    set war_modifier := war_modifier + 5
  endif
  if (bool_Race_Ground_Combat_Poor) then
    set war_modifier := war_modifier + 10
    set treaty_modifier := treaty_modifier - 5
  endif
  if (bool_Race_Losing_Colonies_In_Combat) then
    set war_modifier := war_modifier + 10
    set treaty_modifier := treaty_modifier - 5
  endif

  // Adjust some of our political values based on the number of wars that we are in
  set lng_Politics_Min_Anger_To_Declare_War := lng_Politics_Min_Anger_To_Declare_War + war_modifier
  set lng_Politics_Min_Anger_To_Break_Treaty := lng_Politics_Min_Anger_To_Break_Treaty + war_modifier
  set lng_Politics_Max_Anger_To_Propose_Treaty := lng_Politics_Max_Anger_To_Propose_Treaty + treaty_modifier

  // Debug output
  call Sys_Debug_Print("Politics", "----------------------------")
  call Sys_Debug_Print("Politics", "  - Main Political Modifiers")
  call Sys_Debug_Print("Politics", "    - War Min Anger Level = " + Sys_Convert_Long_To_String(lng_Politics_Min_Anger_To_Declare_War))
  call Sys_Debug_Print("Politics", "    - Break Treaty Min Anger Level = " + Sys_Convert_Long_To_String(lng_Politics_Min_Anger_To_Break_Treaty))
  call Sys_Debug_Print("Politics", "    - Propose Treaty Max Anger Level = " + Sys_Convert_Long_To_String(lng_Politics_Max_Anger_To_Propose_Treaty))

  return TRUE
end

//------------------------------------------------------------------------
// AI_Set_Political_Treaty_Elements
//------------------------------------------------------------------------
function AI_Set_Political_Treaty_Elements returns boolean
params
vars
begin

  // Set our maximum allowed anger for treaty elements

  // Element 1 - Trade Percentage
  // 2% Trade (Index 1)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_TRADE_PERCENT)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(60)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // 4% Trade (Index 2)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_TRADE_PERCENT)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(50)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // 6% Trade (Index 3)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_TRADE_PERCENT)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(40)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // 8% Trade (Index 4)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_TRADE_PERCENT)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(4)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(30)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // 10% Trade (Index 5)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_TRADE_PERCENT)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(5)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(20)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // 12% Trade (Index 6)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_TRADE_PERCENT)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(6)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(10)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // Element 2 - Non-Aggression
  // Non-Aggression in non-colony systems (Index 7)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_NON_AGGRESSION)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(100)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // Non-Agression in all systems (Index 8)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_NON_AGGRESSION)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(80)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // Allow colonization in each other's systems (Index 9)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_NON_AGGRESSION)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(40)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // Element 3 - Mutual-Defense Pact (Index 10)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_MUTUAL_DEFENSE_PACT)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(40)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // Element 4 - Migration
  // Migration from A to B (Index 11)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_ALLOW_MIGRATION_BETWEEN_COLONIES)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(15)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-3)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(4)

  // Migration from B to A (Index 12)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_ALLOW_MIGRATION_BETWEEN_COLONIES)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(15)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-3)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-3)

  // Migration between both A & B (Index 13)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_ALLOW_MIGRATION_BETWEEN_COLONIES)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(30)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // Element 5 - Can make Treaties/Alliances with others
  // A cannot make Treaties with others (Index 14)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_TREATIES_WITH_OTHERS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(10)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-5)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(5)

  // A cannot make Treaties or join Alliances (Index 15)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_TREATIES_WITH_OTHERS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(10)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-5)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(4)

  // B cannot make Treaties with others (Index 16)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_TREATIES_WITH_OTHERS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(10)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-55)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-5)

  // B cannot make Treaties or join Alliances (Index 17)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_TREATIES_WITH_OTHERS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(4)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(10)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-4)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-4)

  // Both A & B cannot make Treaties with others (Index 18)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_TREATIES_WITH_OTHERS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(5)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(20)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-4)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // Both A & B cannot make Treaties or join Alliances (Index 19)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_TREATIES_WITH_OTHERS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(6)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(20)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-4)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // Element 6 - Share Resupply
  // Resupply from A to B only (Index 20)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_RESUPPLY)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(20)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-1)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(1)

  // Resupply from B to A only (Index 21)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_RESUPPLY)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(20)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-1)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-1)

  // Resupply between both A & B (Index 22)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_RESUPPLY)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(40)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // Element 7 - Share Repair
  // Repair from A to B only (Index 23)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_REPAIR)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(20)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-1)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(1)

  // Repair from B to A only (Index 24)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_REPAIR)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(20)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-1)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-1)

  // Repair between both A & B (Index 25)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_REPAIR)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(40)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // Element 8 - Share Technology
  // Technology (4 levels old) from A to B only (Index 26)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_TECHNOLOGY)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(15)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-2)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(2)

  // Technology (2 levels old) from A to B only (Index 27)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_TECHNOLOGY)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(10)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-3)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(3)

  // Technology (current) from A to B only (Index 28)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_TECHNOLOGY)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(5)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-4)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(4)

  // All technology from A to B only (Index 29)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_TECHNOLOGY)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(4)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(0)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-5)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(5)

  // Technology (4 levels old) from B to A only (Index 30)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_TECHNOLOGY)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(5)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(15)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-2)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-2)

  // Technology (2 levels old) from B to A only (Index 31)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_TECHNOLOGY)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(6)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(10)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-3)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-3)

  // Technology (current) from B to A only (Index 32)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_TECHNOLOGY)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(7)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(5)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-4)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-4)

  // All technology from B to A only (Index 33)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_TECHNOLOGY)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(8)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(0)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-5)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-5)

  // Technology (4 levels old) between A & B (Index 34)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_TECHNOLOGY)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(9)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(30)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // Technology (2 levels old) between A & B (Index 35)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_TECHNOLOGY)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(10)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(20)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // Technology (current) between A & B (Index 36)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_TECHNOLOGY)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(11)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(10)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(4)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // All technology between both A & B (Index 37)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_TECHNOLOGY)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(12)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(5)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(5)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // Element 9 - Share System Maps
  // Share Maps from A to B only (Index 38)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_SYSTEM_MAPS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(40)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-1)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(1)

  // Share Maps from B to A only (Index 39)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_SYSTEM_MAPS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(40)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-1)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-1)

  // Share Maps between both A & B (Index 40)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_SYSTEM_MAPS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(60)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // Element 10 - Share Communication Channels
  // Share Channels from A to B only (Index 41)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_COMMUNICATION_CHANNELS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(30)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-1)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(1)

  // Share Channels from B to A only (Index 42)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_COMMUNICATION_CHANNELS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(30)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-1)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-1)

  // Share Channels between both A & B (Index 43)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_COMMUNICATION_CHANNELS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(40)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // Element 11 - Share Espionage Info
  // Share Espionage info from A to B only (Index 44)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_ESPIONAGE_INFO)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(20)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-1)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(1)

  // Share Espionage info from B to A only (Index 45)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_ESPIONAGE_INFO)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(20)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-1)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-1)

  // Share Espionage info between both A & B (Index 46)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_ESPIONAGE_INFO)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(40)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // Element 12 - Share Sensor Data
  // Share Sensor data from A to B only (Index 47)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_SENSOR_INFO)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(20)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-2)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(3)

  // Share Sensor (including cloaked) from A to B only (Index 48)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_SENSOR_INFO)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(10)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-3)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(4)

  // Share Sensor data from B to A only (Index 49)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_SENSOR_INFO)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(20)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-2)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-3)

  // Share Sensor (including cloaked) from B to A only (Index 50)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_SENSOR_INFO)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(4)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(10)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-3)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-4)

  // Share Sensor data between both A & B (Index 51)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_SENSOR_INFO)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(5)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(40)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // Share Sensor (including cloaked) between both A & B (Index 52)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_SENSOR_INFO)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(6)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(20)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // Element 13 - Share Vehicle Designs
  // A gives enemy designs to B (Index 53)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_DESIGNS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(20)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(0)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(1)

  // A gives all designs to B (Index 54)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_DESIGNS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(10) 
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(0)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(3)

  // B gives enemy designs to A (Index 55)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_DESIGNS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(20)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(0)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-1)

  // B gives all designs to A (Index 56)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_DESIGNS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(4)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(10)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(0)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-3)

  // Both A & B share enemy designs (Index 57)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_DESIGNS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(5)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(50)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // Both A & B share all designs (Index 58)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_DESIGNS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(6)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(20)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // Element 14 - Share Minefield Codes
  // A shares Minefield codes with B only (Index 59)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_CODES_FOR_MINEFIELDS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(10)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-2)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(4)

  // B shares Minefield codes with A only (Index 60)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_CODES_FOR_MINEFIELDS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(10)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-2)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-4)

  // Both A & B share Minefield codes (Index 61)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_CODES_FOR_MINEFIELDS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(50)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // Element 15 - Share Combat Reports
  // A shares Combat Reports with B only (Index 62)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_COMBAT_REPORTS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(20)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(0)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(2)

  // B shares Combat Reports with A only (Index 63)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_COMBAT_REPORTS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(20)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(0)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-2)

  // Both A & B share Combat Reports (Index 64)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_COMBAT_REPORTS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(40)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // Element 16 - Cannot perform Research
  // A cannot perform Research, but B can (Index 65)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_CANNOT_RESEARCH)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(-1)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-4)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(5)

  // B cannot perform Research, but A can (Index 66)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_CANNOT_RESEARCH)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(-1)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-4)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-5)

  // Both A & B cannot perform Research (Index 67)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_CANNOT_RESEARCH)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(-1)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-3)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // Element 17 - Cannot perform Intelligence
  // A cannot perform Intel, but B can (Index 68)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_CANNOT_INTELLIGENCE)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(-1)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-4)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(5)

  // B cannot perform Intel, but A can (Index 69)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_CANNOT_INTELLIGENCE)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(-1)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-4)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-5)

  // Both A & B cannot perform Intel (Index 70)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_CANNOT_INTELLIGENCE)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(10)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-3)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // Element 18 - Cannot Bombard Planets
  // A cannot bombard planets, but B can (Index 71)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_CANNOT_BOMBARD_PLANETS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(0)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-3)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(4)

  // B cannot bombard planets, but A can (Index 72)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_CANNOT_BOMBARD_PLANETS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(0)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-3)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-4)

  // Both A & B cannot bombard planets (Index 73)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_CANNOT_BOMBARD_PLANETS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(10)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-2)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // Element 19 - Cannot use Viral Weapons
  // A cannot use viral weapons, but B can (Index 74)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_CANNOT_USE_VIRAL_WEAPONS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(30)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-2)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(2)

  // B cannot use viral weapons, but A can (Index 75)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_CANNOT_USE_VIRAL_WEAPONS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(30)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-2)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-2)

  // Both A & B cannot use viral weapons (Index 76)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_CANNOT_USE_VIRAL_WEAPONS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(50)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // Element 20 - Cannot destroy Planets
  // A cannot destroy planets, but B can (Index 77)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_CANNOT_DESTROY_PLANETS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(0)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-3)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(1)

  // B cannot destroy planets, but A can (Index 78)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_CANNOT_DESTROY_PLANETS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(0)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-3)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-1)

  // Both A & B cannot destroy planets (Index 79)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_CANNOT_DESTROY_PLANETS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(50)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // Element 21 - Cannot destroy Stars
  // A cannot destroy stars, B can (Index 80)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_CANNOT_DESTROY_STARS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(0)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-3)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(4)

  // B cannot destroy stars, A can (Index 81)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_CANNOT_DESTROY_STARS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(0)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-3)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-4)

  // Both A & B cannot destroy stars (Index 82)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_CANNOT_DESTROY_STARS)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(50)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // Element 22 - Cannot Create Blackholes
  // A cannot create blackholes, but B can (Index 83)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_CANNOT_CREATE_BLACKHOLES)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(0)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-3)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(4)

  // B cannot create blackholes, but A can (Index 84)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_CANNOT_CREATE_BLACKHOLES)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(0)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-3)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-4)

  // Both A & B cannot create blackholes (Index 85)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_CANNOT_CREATE_BLACKHOLES)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(50)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // Element 23 - Cannot Create Nebulae
  // A cannot create nebulae, but B can (Index 86)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_CANNOT_CREATE_NEBULAE)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(0)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-3)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(4)

  // B cannot create nebulae, but A can (Index 87)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_CANNOT_CREATE_NEBULAE)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(0)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-3)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-4)

  // A & B cannot create nebulae (Index 88)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_CANNOT_CREATE_NEBULAE)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(50)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // Element 24 - Cannot Use Cloaking
  // A cannot use Cloaks, but B can (Index 89)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_CANNOT_USE_CLOAKING)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(10)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-3)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(3)

  // B cannot use Cloaks, but A can (Index 90)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_CANNOT_USE_CLOAKING)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(10)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-3)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-3)

  // Both A & B cannot use Cloaks (Index 91)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_CANNOT_USE_CLOAKING)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(50)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  // Element 25 - Resource Tariff
  // A pays 5% Tribute to B (Index 92)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_RESOURCE_TARIFF)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(30)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-1)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(1)

  // A pays 10% Tribute to B (Index 93)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_RESOURCE_TARIFF)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(25)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-2)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(2)

  // A pays 15% Tribute to B (Index 94)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_RESOURCE_TARIFF)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(20)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-2)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(3)

  // A pays 20% Tribute to B (Index 95)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_RESOURCE_TARIFF)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(4)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(15)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-3)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(3)

  // A pays 25% Tribute to B (Index 96)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_RESOURCE_TARIFF)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(5)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(15)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-3)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(4)

  // A pays 30% Tribute to B (Index 97)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_RESOURCE_TARIFF)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(6)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(10)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-4)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(4)

  // A pays 40% Tribute to B (Index 98)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_RESOURCE_TARIFF)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(7)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(5)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-4)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(5)

  // A pays 50% Tribute to B (Index 99)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_RESOURCE_TARIFF)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(8)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(0)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-5)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(6)

  // B pays 5% Tribute to A (Index 100)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_RESOURCE_TARIFF)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(9)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(30)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-1)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-1)

  // B pays 10% Tribute to A (Index 101)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_RESOURCE_TARIFF)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(10)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(25)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-2)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-2)

  // B pays 15% Tribute to A (Index 102)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_RESOURCE_TARIFF)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(11)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(20)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-2)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-3)

  // B pays 20% Tribute to A (Index 103)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_RESOURCE_TARIFF)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(12)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(15)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-3)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-3)

  // B pays 25% Tribute to A (Index 104)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_RESOURCE_TARIFF)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(13)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(15)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-3)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-4)

  // B pays 30% Tribute to A (Index 105)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_RESOURCE_TARIFF)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(14)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(10)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-4)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-4)

  // B pays 40% Tribute to A (Index 106)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_RESOURCE_TARIFF)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(15)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(5)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-4)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-5)

  // B pays 50% Tribute to A (Index 107)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_RESOURCE_TARIFF)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(16)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(0)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-5)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-6)
  
  // Element 26 - Share Medical Care
  // Share from A to B only (Index 108)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_PLAGUE_CURING)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(20)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-1)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(1)

  // Share from B to A only (Index 109)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_PLAGUE_CURING)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(2)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(20)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(-1)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(-1)
  
  // Share between both A & B (Index 110)
  call lng_Politics_Treaty_Elements_Allowed_Type.add(TREATY_ELEMENT_TYPE_SHARE_PLAGUE_CURING)
  call lng_Politics_Treaty_Elements_Allowed_Value.add(3)
  call lng_Politics_Treaty_Elements_Allowed_Max_Anger.add(60)
  call lng_Politics_Treaty_Elements_Allowed_Friendship_Value.add(1)
  call lng_Politics_Treaty_Elements_Allowed_Concession_Value.add(0)

  return TRUE
end

//------------------------------------------------------------------------
// AI_Set_Political_Alliance_Elements
//------------------------------------------------------------------------
function AI_Set_Political_Alliance_Elements returns boolean
params
vars
begin

  // Set our maximum allowed anger amounts for Alliance elements

  // Alliance Rule - Votes per Empire
  // 1 Vote per Empire (Index 1) - 1 vote per Empire
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_VOTE_BASIS)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(1)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(60)

  // 1 Vote per Colony (Index 2)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_VOTE_BASIS)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(2)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(50)

  // 1 Vote per 1B population (Index 3)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_VOTE_BASIS)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(3)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(10)

  // 1 Vote per 1000 score (Index 4)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_VOTE_BASIS)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(4)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(10)

  // Alliance Rule - Proposal Passage
  // 50% to pass (Index 5) - 50% to pass
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_PROPOSAL_PASSAGE)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(1)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(40)

  // 60% to pass (Index 6) - 60% to pass
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_PROPOSAL_PASSAGE)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(2)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(50)

  // 70% to pass (Index 7) - 70% to pass
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_PROPOSAL_PASSAGE)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(3)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(60)

  // 80% to pass (Index 8)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_PROPOSAL_PASSAGE)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(4)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(60)

  // 90% to pass (Index 9)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_PROPOSAL_PASSAGE)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(5)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(60)

  // 100% to pass (Index 10)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_PROPOSAL_PASSAGE)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(6)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(60)

  // Alliance Rule - New Members
  // No new members (Index 11)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_NEW_MEMBERS)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(1)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(10)

  // 1 member per year (Index 12)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_NEW_MEMBERS)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(2)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(40)

  // 1 member per 5 years (Index 13)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_NEW_MEMBERS)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(3)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(15)

  // Option 4 (Index 14)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_NEW_MEMBERS)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(4)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(50)

  // Alliance Rule - Trade Percent
  // 5% Trade (Index 15)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_TRADE_PERCENT)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(1)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(50)

  // 10% Trade (Index 16)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_TRADE_PERCENT)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(2)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(45)

  // 15% Trade (index 17)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_TRADE_PERCENT)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(3)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(40)

  // 20% Trade (Index 18)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_TRADE_PERCENT)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(4)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(35)

  // 25% Trade (Index 19)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_TRADE_PERCENT)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(5)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(30)

  // 30% Trade (Index 20)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_TRADE_PERCENT)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(6)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(25)

  // Alliance Rule - Non-Aggression
  // In Neutral Space (Index 21)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_NON_AGGRESSION)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(1)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(60)

  // In All Systems (Index 22)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_NON_AGGRESSION)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(2)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(50)

  // Allow Colonization (Index 23)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_NON_AGGRESSION)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(3)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(30)

  // Alliance Rule - Mutual Defense Pact (Index 24)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_MUTUAL_DEFENSE_PACT)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(1)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(30)

  // Alliance Rule - Migration (Index 25)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_ALLOW_MIGRATION_BETWEEN_COLONIES)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(1)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(40)

  // Alliance Rule - Share Resupply (Index 26)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_SHARE_RESUPPLY)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(1)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(40)

  // Alliance Rule - Share Repair (Index 27)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_SHARE_REPAIR)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(1)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(35)

  // Alliance Rule - Share Plague Cures (Index 28)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_SHARE_PLAGUE_CURING)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(1)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(35)

  // Alliance Rule - Share Technology
  // Share 4 level old (Index 29)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_SHARE_TECHNOLOGY)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(1)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(45)
  // Share 2 level old (Index 30)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_SHARE_TECHNOLOGY)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(2)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(35)
  // Share current (Index 31)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_SHARE_TECHNOLOGY)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(3)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(25)
  // Share all (Index 32)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_SHARE_TECHNOLOGY)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(4)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(15)

  // Alliance Rule - Share System Maps (Index 33)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_SHARE_SYSTEM_MAPS)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(1)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(35)

  // Alliance Rule - Share Communications Channels (Index 34)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_SHARE_COMMUNICATION_CHANNELS)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(1)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(30)

  // Alliance Rule - Share Espionage Info
  // General espionage only (Index 35)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_SHARE_ESPIONAGE_INFO)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(1)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(35)
  // Secret espionage (Index 36)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_SHARE_ESPIONAGE_INFO)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(2)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(25)

  // Alliance Rule - Share Sensor Info
  // Share non-cloaked sensor information (Index 37)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_SHARE_SENSOR_INFO)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(1)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(35)
  // Share all sensor information (Index 38)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_SHARE_SENSOR_INFO)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(2)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(25)

  // Alliance Rule - Share Design Info
  // Share all enemy designs (Index 39)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_SHARE_DESIGNS)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(1)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(35)
  // Share all designs (Index 40)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_SHARE_DESIGNS)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(2)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(25)

  // Alliance Rule - Share Combat Reports (Index 41)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_SHARE_COMBAT_REPORTS)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(1)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(30)

  // Alliance Rule - Share Minefield Codes (Index 42)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_SHARE_CODES_FOR_MINEFIELDS)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(1)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(25)

  // Alliance Rule - No Research (Index 43)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_CANNOT_RESEARCH)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(1)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(10)

  // Alliance Rule - No Intelligence (Index 44)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_CANNOT_INTELLIGENCE)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(1)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(10)

  // Alliance Rule - Can't Bombard Planets (Index 45)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_CANNOT_BOMBARD_PLANETS)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(1)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(15)

  // Alliance Rule - Can't Use Viral Weapons (Index 46)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_CANNOT_USE_VIRAL_WEAPONS)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(1)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(15)

  // Alliance Rule - Can't Destroy Planets (Index 47)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_CANNOT_DESTROY_PLANETS)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(1)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(15)

  // Alliance Rule - Can't Destroy Stars (Index 48)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_CANNOT_DESTROY_STARS)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(1)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(15)

  // Alliance Rule - Can't Create Black Holes (Index 49)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_CANNOT_CREATE_BLACKHOLES)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(1)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(15)

  // Alliance Rule - Can't Create Nebulae (Index 50)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_CANNOT_CREATE_NEBULAE)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(1)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(15)

  // Alliance Rule - Can't Use Cloaking (Index 51)
  call lng_Politics_Alliance_Elements_Allowed_Type.add(ALLIANCE_RULE_TYPE_CANNOT_USE_CLOAKING)
  call lng_Politics_Alliance_Elements_Allowed_Value.add(1)
  call lng_Politics_Alliance_Elements_Allowed_Max_Anger.add(15)

  return TRUE
end